Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
garyfitzwater3
Courses Plus Student 1,666 PointsNeed help with error on line 22
//Question 1
//prompt asking question
var addition = prompt("If I add 7 + 7 what do I get?");
//parse from string to integer
var addInt = parseInt(addition);
//conditional statement
if (addInt === 14){
// adding score
yourscore += 1
//conditional responses true or false
alert("That is a correct answer! score = " + yourScore);
}else{
alert("Sorry that is incorrect! score = " + yourScore);
}
//Question 2
//prompt asking question
var subtraction = prompt("If I subtract 5 - 3 what do I get?");
//parse from string to integer
var subInt = parseInt(subtraction);
//conditional statement
if (subInt === 2){
// adding score
yourscore += 1
//conditional responses true or false
alert("That is a correct answer! score = " + yourScore);
}else{
alert("Sorry that is incorrect! score = " + yourScore);
}
//Question 3
//prompt asking question
var multiply = prompt("If I multiply 5 * 5 what do I get?");
//parse from string to integer
var multInt = parseInt(multiply);
//conditional statement
if (multInt === 25){
// adding score
yourscore += 1
//conditional responses true or false
alert("That is a correct answer! score = " + yourScore);
}else{
alert("Sorry that is incorrect! score = " + yourScore);
}
//Question 4
//prompt asking question
var addition2 = prompt("If I add 3 + 9 what do I get?");
//parse from string to integer
var add2Int = parseInt(addition2);
//conditional statement
if (add2Int === 12){
// adding score
yourscore += 1
//conditional responses true or false
alert("That is a correct answer! score = " + yourScore);
}else{
alert("Sorry that is incorrect! score = " + yourScore);
}
//Question 5
//prompt asking question
var subtract2 = prompt("If I subtract 7 - 2 what do I get?");
//parse from string to integer
var sub2Int = parseInt(subtract2);
//conditional statement
if (sub2Int === 5){
// adding score
yourscore += 1
//conditional responses true or false
alert("That is a correct answer! score = " + yourScore);
}else{
alert("Sorry that is incorrect! score = " + yourScore);
}
// Keep track of the number of questions the user answered correctly
var award
if ( yourscore === 5 ) {
award = "Very Good";
} else if ( yourscore > 2 && yourscore < 5 ) {
award = "Good";
} else if ( yourscore > 0 && yourscore < 3 ) {
award = "Average";
} else {
award = "None!";
}
// Provide a final message after the quiz letting the user know the number of questions he or she got right.
var finished = alert("It's all done you have scored " + yourscore + ". Awarded: " + award);
4 Answers
James Anwyl
Full Stack JavaScript Techdegree Graduate 49,960 PointsHi Gary,
First of all, you need to define yourscore as a variable to avoid the "Uncaught ReferenceError: yourscore is not defined" error.
var yourscore = 0;
Secondly, you had mixed up the casing on your variable names and written yourscore in some places and yourScore in others.
Try this:
var yourscore = 0;
//Question 1
//prompt asking question
var addition = prompt("If I add 7 + 7 what do I get?");
//parse from string to integer
var addInt = parseInt(addition);
//conditional statement
if (addInt === 14){
// adding score
yourscore += 1;
//conditional responses true or false
alert("That is a correct answer! score = " + yourscore);
}else{
alert("Sorry that is incorrect! score = " + yourscore);
}
//Question 2
//prompt asking question
var subtraction = prompt("If I subtract 5 - 3 what do I get?");
//parse from string to integer
var subInt = parseInt(subtraction);
//conditional statement
if (subInt === 2){
// adding score
yourscore += 1;
//conditional responses true or false
alert("That is a correct answer! score = " + yourscore);
}else{
alert("Sorry that is incorrect! score = " + yourscore);
}
//Question 3
//prompt asking question
var multiply = prompt("If I multiply 5 * 5 what do I get?");
//parse from string to integer
var multInt = parseInt(multiply);
//conditional statement
if (multInt === 25){
// adding score
yourscore += 1;
//conditional responses true or false
alert("That is a correct answer! score = " + yourscore);
}else{
alert("Sorry that is incorrect! score = " + yourscore);
}
//Question 4
//prompt asking question
var addition2 = prompt("If I add 3 + 9 what do I get?");
//parse from string to integer
var add2Int = parseInt(addition2);
//conditional statement
if (add2Int === 12){
// adding score
yourscore += 1;
//conditional responses true or false
alert("That is a correct answer! score = " + yourscore);
}else{
alert("Sorry that is incorrect! score = " + yourscore);
}
//Question 5
//prompt asking question
var subtract2 = prompt("If I subtract 7 - 2 what do I get?");
//parse from string to integer
var sub2Int = parseInt(subtract2);
//conditional statement
if (sub2Int === 5){
// adding score
yourscore += 1;
//conditional responses true or false
alert("That is a correct answer! score = " + yourscore);
}else{
alert("Sorry that is incorrect! score = " + yourscore);
}
// Keep track of the number of questions the user answered correctly
var award
if ( yourscore === 5 ) {
award = "Very Good";
} else if ( yourscore > 2 && yourscore < 5 ) {
award = "Good";
} else if ( yourscore > 0 && yourscore < 3 ) {
award = "Average";
} else {
award = "None!";
}
// Provide a final message after the quiz letting the user know the number of questions he or she got right.
var finished = alert("It's all done you have scored " + yourscore + ". Awarded: " + award);
Hope this helps :)
EDIT: As Vladut pointed out, you are missing semicolons from some of your statements. This won't cause errors in this circumstance, but can do in others and it's considered a best practice.
Vladut Astalos
11,246 PointsYou missed semicolon after 'yourscore += 1'.
garyfitzwater3
Courses Plus Student 1,666 PointsTried that still didn't work " yourscore += 1; "
garyfitzwater3
Courses Plus Student 1,666 PointsAh right excellent thanks for that it really helped.