Here is my code:
let guessTheNumber = () => {
let randomNumber = Math.round((Math.random()) * 10); //generating a random number from 1 to 10
console.log(randomNumber); //added this just to see what number was generated
let question = +prompt('Please, try to guess the number from 1 to 10!'); // by using unary plus I want prompt to return a number, NOT a string
if (question === randomNumber) {
alert('Wow, you are quite lucky. Nice job!'); //this one works
}
else if (question !== randomNumber) {
alert('Nope'); //this one is also easy to check
}
else if (question === "") {
alert('You did not enter anything!');
}
else {
alert('Why did you cancel?');
}
}
guessTheNumber();
I can successfully check the question
when it equals to randomNumber
variable or not. But when I try to alert something, if there is an empty string (clicking "OK" without any input) or null (clicking "Cancel"), the Program fails.