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

Jason Styron
PLUS
Jason Styron
Courses Plus Student 955 Points

Conditional Statements Quiz Challenge

I made up my own questions for this quiz however I could not get the code to run. I then went back and copied the code shown in the video. I saved and previewed but prompt boxes are not showing to move through the quiz. I am not sure what I am doing wrong. I did try the console but it didn't show the error. Thanks for your time in advance.

var correct = 0;

// ask questions var answer1 = prompt("Name a programming language that's also a gem"); if (answer1.toUpperCase() === 'RUBY') { correct += 1; } var answer2 = prompt("Name a programming language that's also a snake"); if (answer2.toUpperCase === 'PYTHON') { correct += 1; } var answer3 = prompt("What language do you use to style web pages?'); if (answer3.toUpperCase === 'CSS') { correct += 1; } var answer4 = prompt("What language do you use to build the structure of the web pages?"); if (answer4.toUpperCase === 'HTML') { correct += 1; } var answer5 = prompt("What language do you use to add interactivity to a web page?"); if (answer5.toUpperCase === 'JAVASCRIPT') { correct += 1; }

// output results document.write(<p>You got " + correct + " out of 5 questions correct.<p>");

// output results 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>); }

2 Answers

The console shows you have 3 errors:

(1) Prompt begins with double quotes but ends in single quote

var answer3 = prompt("What language do you use to style web pages?');

(2) What you are passing to document.write needs to be enclodes in quotes

// output results
document.write(<p>You got " + correct + " out of 5 questions correct.</p>");

should be

.write("<p>

note: I fixed the closing </p> tag as well.

(3) Same here with document.write. There is a beginning quote but no end quote.

document.write("<p><strong>No crown for you!</strong></p>);  

In addition to this toUpperCase() is missing the parentheses in 4 of the 5 questions. This will lead to the incorrect count of correct answers being displayed.

Jason Styron
Jason Styron
Courses Plus Student 955 Points

Thank you. I should have looked a little harder.

Shlomi Bittan
Shlomi Bittan
6,718 Points

Hi Jason, You many problems in your code...

  1. document.write(<p>You got " + correct + " out of 5 questions correct.<p>"); There is only a closing double quote. You forgot the first one in the beginning.
  2. document.write("<p><strong>No crown for you!</strong></p>); same as 1, only this time it is the closing quotaston mark that is missing.
  3. answer.toUpperCase() - only the first if statement is correct. You forgot '()' at the rest of the statements.
  4. var answer3 = prompt("What language do you use to style web pages?'); As you can see the string quotation starts with a double quotation mark and ends with a single one.