Out of topic (PROMPT FUNCTION


#1

Here is a code.
I wanna to prompt a var's result but it's not working.

How can I code it

var firstNumber = Math.floor(Math.random()*5)+1;
var secondNumber =Math.floor(Math.random()*5)+1;

console.log(firstNumber);
console.log(secondNumber);

var userAnswer = prompt("What will be" firstNumber "+" secondNumber);
if (userAnser === firstNumber+secondNumber) {
document.write("Your answer is true!");
}
else {
document.write("You have to try again! Refresh the page!");
}


#2

you have spelt the last userAnswer incorrectly.


#3

I make it correct later, even in that case it's not working...
upto console.log its fine. but when I declare userAnswer the prompt function not appears,


#4

You need the plus signs in the prompt..

Should read something similar to:

var userAnswer = prompt("What will be " + firstNumber + "+ " + secondNumber);

Hope that helps!


#5

here is working code.

var firstNumber = Math.floor(Math.random()*100)+1;
var secondNumber =Math.floor(Math.random()*100)+1;

var userAnswer = prompt("What will be the " + firstNumber + "+" + secondNumber);
var result = firstNumber + secondNumber;
console.log(result);
console.log(userAnswer); 
if (result == userAnswer) {

	document.write("You are totally right. The right answer is " + result)
}
else {

	document.write("I think you should try again, to do it just refresh the page!");
}