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
sonjajordan
5,106 PointsI don't know why my quiz won't run. Can I get help with it?
//Quiz begins var correct = 0;
//Ask questions
var ques1 = prompt('How many states begin with the letter M?');
if (ques1 === '8') {
correct += 1;
}
var ques2 = prompt('How many states begin with the letter L?');
if (ques2 === '1') {
correct += 1;
}
var ques3 = prompt('How many states begin with the letter S?'); if (ques3 === '2') { correct += 1; } var ques4 = prompt('How many states begin with the letter F?'); if (ques4 === '1') { correct += 1; } var ques5 = prompt('How many states begin with the letter N?'); if (ques5 === '4') { correct += 1; }
// Output results document.write('<p>You got' + correct + 'out of 5 correct.<p>');
//Output rank if(correct===5) { document.write('<p><strong>You earned a gold crown!<strong></p>'); } else if (correct===3) { document.write('<p><strong>You earned a silver 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>');
3 Answers
Matthew Lanin
Full Stack JavaScript Techdegree Student 8,003 PointsI'm not sure if the copy and paste put the "//" on the same lines as some of your declarations, conditional statements, but just to be sure, anything following a "//" and on the same line will not run. So make sure in your editor/workspace, code that you want run isn't on the same line.
If that wasn't the case, it looks like you are missing a final closing "}" at the very end, to close your final else statement.
//Quiz begins
var correct = 0;
//Ask questions
var ques1 = prompt("How many states begin with the letter M?");
if (ques1 === "8") {
correct += 1;
}
var ques2 = prompt("How many states begin with the letter L?");
if (ques2 === "1") {
correct += 1;
}
var ques3 = prompt("How many states begin with the letter S?");
if (ques3 === "2") {
correct += 1;
}
var ques4 = prompt("How many states begin with the letter F?");
if (ques4 === "1") {
correct += 1;
}
var ques5 = prompt("How many states begin with the letter N?");
if (ques5 === "4") {
correct += 1;
}
// Output results
document.write("<p>You got" + correct + "out of 5 correct.<p>");
//Output rank
if (correct === 5) {
document.write("<p><strong>You earned a gold crown!<strong></p>");
} else if (correct === 3) {
document.write("<p><strong>You earned a silver 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>");
}
With the added closing curly brace, it looks like it is running just fine. You are going to want to add some spaces to this line,
document.write('<p>You got' + correct + 'out of 5 correct.<p>');
in order for it to look the way you want.
sonjajordan
5,106 PointsOk, thank you. I will correct it.
Matthew Lanin
Full Stack JavaScript Techdegree Student 8,003 PointsSure thing, good work on the rest of it.
Teresa Balistreri
6,714 PointsThe only things I notice are that the final closing </p> is missing the / (<p> instead of </p>), and some of the closing </strong> tags are missing the forward slashes. But I don't think that would cause it to not run. But do you notice your final document.write is unintentionally bold?