I would like a user to input a number. If number is between 1 and 100, I would alert with message "Great". If input is below 1 and more than 100, I would alert "Please, only numbers between 1-100. I am having two problems here:
-
My conditions with comparison operators do not work. No matter what number I enter more than 100 or less than 100, I still get the same message. I just wonder if someone could point where is the error.
-
The second problem is that I can even enter letters. When I enter letters, it just goes to the second alert message "Please, only numbers from 1-100".
What is the easiest way to make user to enter numbers only, not letters or other symbols, and alert them to enter only digits.
var userInput = prompt('Enter a number'); // asking user to input a number
if (userInput<=100 || userInput>=1) {
alert ('Great !');}
if(userInput <1 && userInput > 100);
{
alert('Please, only numbers betwen 1-100'); }
Aucun commentaire:
Enregistrer un commentaire