Math Test is saying wrong score and I don't know why


#1

confirm("Are you ready to take the test?");
var ready = function() {
confirm("Are you ready for the next question?");
};
var add = p1 + p2 + p3;

var q1 = prompt("What is 5(x) where x = 5");
if (q1 === "25") {
var p1 = 1;
} else {
var p1 = 0;
}

ready();
var q2 = prompt("(x + 5) + (x - 2) Where x = 10");
if (q2 === "23") {
var p2 = 1;
} else {
var p2 = 0;
}

ready();
var q3 = prompt("5 + 10 / 2");
if (q3 === "10") {
var p3 = 1;
} else {
var p3 = 0;
}

var passOrNot = (p1 + p2 + p3);
if (passOrNot >= 2) {
confirm("You passed! Congrats");
} else {
confirm("Sorry, but you did not pass.");
}
console.log("Your score: " + add + "/3");


#2

Hey this is your problem: You defined add at the top so it cant understand it on the bottom. So just define it at the bottom and you will be fine Hope this helped!

confirm("Are you ready to take the test?");
var ready = function() { 
confirm("Are you ready for the next question?"); 
};


var q1 = prompt("What is 5(x) where x = 5");
if (q1 === "25") { 
var p1 = 1; 
} else { 
var p1 = 0; 
}

ready();
var q2 = prompt("(x + 5) + (x - 2) Where x = 10");
if (q2 === "23") {
var p2 = 1; 
} else {
var p2 = 0; 
}

ready();
var q3 = prompt("5 + 10 / 2");
if (q3 === "10") {
var p3 = 1; 
} else {
var p3 = 0; 
}

var passOrNot = (p1 + p2 + p3);
if (passOrNot >= 2) {
confirm("You passed! Congrats"); 
} else {
confirm("Sorry, but you did not pass."); 
}
var add = p1 + p2 + p3;
console.log("Your score: " + add + "/3");

#3

Thanks! That worked perfectly.:smile: