Answer the question
In order to leave comments, you need to log in
Why is counter not working in javascript?
wrote counter. I answer correctly to all riddles 4 out of 4, and the counter gives out 3 correct answers as a result. if I answer correctly less, I think it's true. it does not count all 4.
varquest = 0;
var ansv;
var name = prompt("Hello. What's your name?");
var vopros = prompt(name + ", " + "let's play riddles?");
if (vopros == "yes") {
alert("Let's go!");
ansv = prompt("Riddle #1" + "\n" + "This number looks so much like" + "\n" + "It looks like a beautiful sail!" + "\n" + "It's getting bigger and bigger" + "\n" + "Number ...").toLowerCase();
if (ansv == "four") {
quest = quest + 1;
alert("Correct");
}
else
alert("Invalid");
ansv = prompt("Riddle No. 2" + "\n" + "There is a turtle - a steel shirt," + "\n" + "The enemy is in the ravine - and where is the enemy?").toLowerCase();
if (ansv == "tank") {
quest = quest + 1;
alert("Correct");
}
else
alert("Invalid");
ansv = prompt("Riddle #3" + "\n" + "Guess the riddle: Who's got a heel behind their nose?").toLowerCase();
if (ansv == "shoes") {
quest = quest + 1;
alert("Correct");
}
else
alert("Invalid");
ansv = prompt("Riddle #4" + "\n" + "
alert("Correct");
}
else
alert("Invalid");
if (quest <= 2) {
alert("Number of correct answers = " + quest + "\n" + name + ", " + "children know more than you! Shame!");
}
else if (quest = 3 ) {
alert(name + ", " + "number of correct answers = " + quest);
}
else if (quest = 4) {
alert("Number of correct answers = " + quest + "\n" + name + ", " + "ha! Pretty smart!");
}
}
else
alert(name + ", " + "you're a coward!");
Answer the question
In order to leave comments, you need to log in
At least write the correct check, not assignment: else if (quest = 3 ) to else if (quest == 3 )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question