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 Solution

Julia Rix
Julia Rix
3,303 Points

Workspaces hates me or my code. Quiz Challenge Question

I created my quiz and tried to run it. No go. So then I watched Dave's video and realized I had put too much code in there, so I simplified it using his structure. It still won't run. It is on par with others' quizzes. If anyone can take a look and tell me where I went wrong. I would appreciate it so much!!! Going grey, Julia

var correctAnswer = 0;

// ask Questions var answer1 = prompt('What is the capital of MA?'); if (answer1 === 'Boston'){ correctAnswer +=1; }

var answer2 = prompt('What is the capital of TN?'); if (answer2 === 'Nashville'){ correctAnswer += 1; }

var answer3 = prompt('What is the capital of FL?'); if (answer3 === 'Tallahassee'){ correctAnswer += 1; }

var answer4 = prompt('What is the capital of VT?'); if (answer4 === 'Montpelier'){ correctAnswer += 1; }

var answer5 = prompt('What is the capital of CA?') if (answer5 === 'Sacramento'){ correctAnswer += 1; }

/* Final Score & Rank */ document.write('Your final score is ' + correctAnswer); if (correctAnswer === 5) { document.write('You win the gold crown!'); }else if (correctAnswer === 3 || 4){ document.write('You win the silver crown!'); }else if (correctAnswer === 1 || 2) { document.write('You win the bronze crown!'); }else (correctAnswer === 0) { document.write('You lose!'); }

5 Answers

Mustafa Başaran
Mustafa Başaran
28,046 Points

Hi Julia,

There are couple of issues that you need to fix in your code. They are

  • You are missing ; at the end of the line below

var answer5 = prompt('What is the capital of CA?')

  • 'else' covers all other possibilities unspecified in a conditional statement. You are not supposed to bring another test in the 'else' part since 'else if' is the way to do that. So, the parentheses in 'else (correctAnswer === 0)' are redundant.

  • After deleting the parentheses (please see above), I checked your code. Although I gave incorrect answers to all questions, I still got a silver crown. So, the conditional challenge is not working properly either.

  • You may want to use the browser console in detecting bugs in JS. The browser console opens with CTRL + SHIFT + J in Chrome and CTRL + SHIFT + K in Firefox. The console indicates the error type as well as the line number where it occured in your quiz.js file.

I hope that this helps. Good luck!

Best regards,

Mustafa

I'm not quite sure what you mean by 'it won't run.' It would be helpful for you to describe the behavior that you see. I'm assuming you don't see any output on the screen. I see a couple things with your code. First, in the last section where you are checking the score, I used code that looked like this: else if (correct === 4 || correct === 3) I think that is the main bug. The other thing you should do is use either toUpperCase() or toLowerCase() in your conditional statements in the first section. It would look like this: answer1.toUpperCase() === 'BOSTON', that way the user doesn't have to match your case exactly. Good luck!

Julia Rix
Julia Rix
3,303 Points

Thank you for your suggestions! I made the changes you suggested and I still get nothing. When I say it won't run, what I meant is that I get no dialogue box with my questions, just a dumb blank page that says Ultimate Quiz Challenge. So it makes me happy to hear that something was working for you Mustafa. The Workspaces was spotty for me throughout the lessons as well. Sometimes it would work just fine and other times. Nothing. I'll keep tinkering with it but thank you so much for trying it!

Julia Rix
Julia Rix
3,303 Points

GOT IT WORKING!!! I had an extra curly brace in line 39. Once I removed that everything worked just fine. Thanks again!

Mustafa Başaran
Mustafa Başaran
28,046 Points

Nice to hear that Julia. You are more than welcome!