Why isn't my prompts / alert sowing up? ALSO INCLUDES HTML

javascript

#1

My code was working a moment ago and was doing what it was suposed to do (asking questions and taking answers then telling you your score at the end). I have no idea what happened and thanks in advance,

-baumy

My code:


#2

if there are syntax problems in your code, it is not going to work, two problems, first your function:

function ask(question, correct) {

the opening curly bracket ({) of your function, doesn't have a matching closing curly bracket, you might want to add this missing curly bracket before you call the function.

Second problem, this line:
alert("Well Done, You got it right!"), score = score + 1;

If you just want to update the score, use a semi-colon (;) after alert, not a regular comma (,)


#3

I would also add, you have used document.getElementById("demo"). However, you have not given any element the Id "demo".


#4

Thanks for the fast response!
Part 1: basically I should have this-

function ask(question, correct) {
var answer=prompt(question);
if(answer==correct){
alert("Well Done, You got it right!"), score = score + 1;
}
else { alert("Sorry that is wrong");
}
}

And part 2: I should have this-

alert("Well Done, You got it right!"); score = score + 1;

Just a question on Part 2: Will the score still be connected to the if if I have a semicolon?

Thanks a lot,
-baumy


#5

Very true! I had a h1 there but I must of deleted it! Thanks for taking the time to look through the code when I don't have the skills to see my own errors,

-baumy


#6

so it works now? Yea, everything between {}:

if(answer==correct){
        alert("Well Done, You got it right!"); score = score + 1;
    } /* end if statement */

will be in the if statement, i put a comment show you where the if statement ends, the } gives the end of a if statement, never a semi-colon