Author Topic: Javascript Problem  (Read 253 times)

I wan't to make it say Correct if the user types in Harrisburg, and Incorrect if the user types in something else

I think I am doing it wrong, because it keeps saying Incorrect.

Code: [Select]
prompt('What is the capitol of Pennsylvania?');
if(prompt === "Harrisburg"){
    confirm('You got it right!');
}
else{
    confirm('Sorry, this is incorrect.');
}

You need to store the answer in a variable, then check the variable.

var answer = prompt('What is the capitol of Pennsylvania?');
if (answer === "Harrisburg") {
    confirm('You got it right!');
}
else {
    confirm('Sorry, this is incorrect.');
}


Quick second question,

How do I make it stop the code completely when the user chooses cancel in the Dialog?