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

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge

Ben Ahlander
Ben Ahlander
7,528 Points

How to keep scoreboard

Here is my Code:

var q1 = prompt("What is 2 + 2?"); var points = 0; if(q1==="4") { alert("That is correct " + "Your score is: " + points+1); } else { alert("Wrong you suck!"); };

var q2 = prompt ("What is Bens favorite company?"); if(q2.toUpperCase()==="TESLA") { alert("That is correct" + "Your score is: " + points+1);
} else { alert("Wrong you suck!"); };

var q3 = prompt ("If a heavy and light object are dropped in a vaccum, will they hit the ground at the same time?"); if(q3.toUpperCase()=== "yes") { alert("That is correct"); } else { alert("Wrong you suck!"); };

var q4 = prompt ("What is 8/2?"); if(q4==="4") { alert("That is correct");
} else { alert("Wrong you suck!"); };

var q5 = prompt ("Did bush do 911?"); if(q5==="No, but he knew about it. You see, Gorge Soros and worked with the Clinton foundation to put chem trails in the air and turn chobani yougurt into neclear cyber sperm that allows the government to listne to your thoughts. DONT EAT THE YOUGURT!") { alert("That is correct");
} else { alert("Wrong you suck! The real answer is No, but he knew about it. You see, Gorge Soros and worked with the Clinton foundation to put chem trails in the air and turn chobani yougurt into neclear cyber sperm that allows the government to listne to your thoughts. DONT EAT THE YOUGURT!"); };

1 Answer

Steven Parker
Steven Parker
231,271 Points

You're not saving the new points values.

When you print "points + 1", it will show a larger value, but it does not save that value back in the variable. But you could replace that with "++points" which would do both.

A more common method would be to do "points += 1;" on a line by itself before the output message, and then in the output just show "points" without adding to it.