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 trialCorinne Jacobs
3,815 PointsWhy is my program not working?
My program is not working right. Even if I miss one or more it says I still get the gold crown. I also checked in the browser to see if there were any errors and there is none in the console. Please help! Code below:
// quiz begins, no answers correct
var correct = 0;
// question one
var answer1 = prompt('What is the best programming language?');
if(answer1 .toUpperCase() === 'JAVASCRIPT');
correct+= 1;
// question 2
var answer2 = prompt('What is my favorite color?');
if(answer2 .toUpperCase () === 'GREEN');
correct+=1;
// question 3
var answer3 = prompt('Name a programming launage that is also a gem?');
if(answer3 .toUpperCase () === 'RUBY');
correct+=1;
// question 4
var answer4 = prompt ('What is my favorite meal?');
if (answer4 .toUpperCase () === 'PASTA');
correct+=1;
// question 5
var answer5 = prompt('What is my favorite drink?');
if (answer5 .toUpperCase () === 'DIET COKE');
correct+=1;
// output results
document.write ("<p>You got " + correct + " out of 5 questions correct.<p>");
//output rank
if ( correct === 5) {
document.write ("<p><strong>You get the gold crown!</strong></p>");
} else if ( correct >= 3 ) {
document.write("<p><strong>You earned a sliver crown.</strong></p>");
} else if (correct >= 1) {
document.write("<p><strong>You earned a bronze crown.</strong></p>");
} else {
document.write ("<p><strong>No crown for you.</strong></p>");
}
1 Answer
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi Corinne,
I added some markup to your code so we could see it a little better. Check out the markdown cheatsheet below to learn how to add code to the forum. :-)
Anyway, at the moment your code is always adding 5 to your variable because you're not adding if blocks to the code properly.
var answer1 = prompt("What is the best programming language?");
if(answer1 .toUpperCase() === "JAVASCRIPT"){
correct+= 1;
}
If you add curly braces like above to each of the questions the score will only be added if the text you add to the prompt matches the condition in your if statement.
Give that a try and good luck. :-)