I am a coding newbie. I am learning JS on Codecademy and I keep getting this error : NS_ERROR_NOT_AVAILABLE
. What am I doing wrong in the following code?
prompt ("Are you ready to play");
confirm ("I am ready to play!");
var age = prompt("What's your age");
if("age" <= 12) {
console.log("Play at your own risk");
} else {
console.log("Play on!");
}
age
is a variable, not a string, there is no need for quotes:
prompt ("Are you ready to play");
confirm ("I am ready to play!");
var age = prompt("What's your age");
if(age <= 12) {
console.log("Play at your own risk");
} else {
console.log("Play on!");
}
You need to use age without the quotes, as you are referencing a variable , not a string
if (age <= 12)
"age" with quotes in javascript means the literal word (or 'string') age, and so comparing "age" with 12 won't get the the result you expected
age without quotes in javascript means whatever value is associated to the variable age
, in this case, whatever the user entered into the prompt()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.