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
Raymond LeDuc
587 PointsThe Conditional Challenge
Completing the challenge and then refreshing the browser the counter/score does not re zero any suggestions?
var score = 0;
crown = ' ';
var answer1 = prompt('1. What is the current language we are learning?');
if (answer1.toLowerCase() ==="javascript"){
alert('Correct');
score += 1;
} else {
alert('That is incorrect.');
}
var answer2 = prompt("2. Whatis the value of '9' + 6?");
if (parseInt(answer2) === 96) {
alert('Correct');
score += 1;
} else {
alert('That is incorrect.');
}
var answer3 = prompt("3. What is the boolean value of !'bang'?");
if (answer3.toLowerCase() ==="false") {
alert('Correct');
score += 1;
} else {
alert('That is incorrect.');
}
var answer4 = prompt("What is the value of parseFloat('12.3.4')?");
if (parseFloat(answer4) === 12.3){
alert('Correct');
score += 1;
} else {
alert('That is incorrect.');
}
var answer5 = prompt("What programming language that's also a gem?");
if (answer5.toUpperCase() === "RUBY"){
alert('Correct');
score += 1;
} else {
alert('That is incorrect.');
}
if (score === 5){
crown = "gold";
} else if (score >= 3){
crown = "silver";
} else if (score = 2){
crown = "bronze";
} else {
document.write("You didn't earn a crown. Try harder next time.")
}
console.log(score);
document.write("You answered " + score + " correct out of 5. " + "You have earned a " + crown + " crown." );
score = 0;
console.log(score);
4 Answers
Andrew Patterson
3,075 PointsWhen I copied this code to the Chrome console, the second to last line 'score = 0' did reset the value of score to 0. It could be a problem with the variable being store in your cookies. Have you tried deleting cookies and browser data? Is there any HTML that should be running alongside this JavaScript? I can run them together in Codepen.io if you'd like.
Best,
Andrew
jared eiseman
29,023 PointsI copied your code and ran it inside a very basic HTML file: html <html> <head> </head> <body> <script src="example.js"></script> </body> </html>
After completing the challenge, and then refreshing my browser everything re-zeroed as expected. Seeing as everything is stored in memory and not being committed to a database, or some other way of storing the data, I'm unsure as to how it would not re-zero for you. What browser are you using, and how are you refreshing the page?
Raymond LeDuc
587 PointsI use chrome and just used the refresh button ( F5 key). I have concluded that yes infact it was stored in the browsers mememory and had to clear it before it would reset. Thanks to you as well for replying as well.
Raymond LeDuc
587 Pointsadded the code to codepen
Raymond LeDuc
587 PointsPS you may be right about it still being in the cookies. I am gonna try that now also
Raymond LeDuc
587 PointsRaymond LeDuc
587 PointsAfter clearing the browsing data it seemed to fix it. I'm sure there will be a work around for this later in the course.
Thanks for your reply.
Andrew Patterson
3,075 PointsAndrew Patterson
3,075 PointsGlad to hear you fixed it! I was wondering if you would be able to mark my answer with the green checkmark for best answer? I need to get a "best answer" to complete my career track!
Thank you,
Andrew