Reputation: 17
var age = '16';
prompt(enter 'age');
if (age > 17) {
alert("good to drive");
} else {
alert("sorry you are not eligible");
}
Upvotes: 0
Views: 431
Reputation: 294
You had a few syntax errors but here's a patched up version:
var age = prompt("Please enter your age"); // Gets input
if (age > 17) {
alert("Good to drive.");
} else {
alert("Sorry you are not eligible.");
}
Upvotes: 1
Reputation: 780909
The first two lines should be:
var age = prompt('enter age');
The whole argument to prompt()
has to be in quotes, and you need to assign the result to the variable so you can use it in the if
statement.
Upvotes: 0