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

John Fulstone
PLUS
John Fulstone
Courses Plus Student 762 Points

Conditional challenge quiz.js

I'm coming up with an error on the last line. What did I do wrong? It is identical to the one in Guil's solution. /*

  1. Store correct answers
    • When quiz begins, no answers are correct */ let correct = 0

// 2. Store the rank of a player

let rank = '';

// 3. Select the <main> HTML element

const main = document.querySelector("main"); /*

  1. Ask at least 5 questions
    • Store each answer in a variable
    • Keep track of the number of correct answers */ const answer1 = prompt("Who will make the best president in 2020?"); { if (answer.toUpperCase() === "Trump") { correct = +1; } const answer2 = prompt("Who is the most vulgar presidential candidate"); { if (answer.toUpperCase() === "Biden") { correct = +1; } const answer3 = prompt("Who was the worst president ever?"); { if (answer.toUpperCase() === "Obama") correct = +1; } const answer4 = prompt("Who was president in 1987?"); { if (answer.toUpperCase() === "Reagan") correct = +1; } const answer5 = prompt("Who would make the best president ever?"); { if (answer.toUpperCase === "John") { correct = +1; }

/*

  1. Rank player based on number of correct answers
    • 5 correct = Gold
    • 3-4 correct = Silver
    • 1-2 correct = Bronze
    • 0 correct = No crown */ if ( correct === 5 ) { rank = "Gold"; } else if ( correct >= 3 ) { rank = "Silver"; } else if ( correct >= 2 ) { rank = "Bronze"; } else { rank = "None"; }

// 6. Output results to the <main> element main.innerHTML = <h2>You got ${correct} out of 5 questions correct.</h2> <p>Crown earned: <strong>${rank}</strong></p> ;

Tobias Edwards
Tobias Edwards
14,458 Points

Would you mind reformatting your code using the markdown cheatsheet?

1 Answer

Cameron Childres
Cameron Childres
11,818 Points

Hey John!

If you use the markdown cheatsheet linked below the comment box we'll be able to read your code more easily and characters won't be dropped when you post, like the `` surrounding your template literal.

I've just had a look at your code and there are a number of places where it does not match the solution. Here are a some things I noticed:

1) Your first variable declaration (let correct = 0) does not end with a semicolon. (Not the worst thing, one will be automatically inserted, but this doesn't always work correctly)

2) Your "if" statements checking answers:

  • start with an extraneous "{",
  • check against an undeclared variable of "answer" instead of "answer1", "answer2", etc
  • convert the answer string to upper case but compare it to a string that is not
  • are missing the "{" that should be preceding "correct" in the third and fourth statement

If you correct these errors your code should run without issue. Let me know if you need any further assistance.

John Fulstone
John Fulstone
Courses Plus Student 762 Points

Thanks Cameron; that helped a lot! I really appreciate your assistance. I'm older than dirt so it takes me a little longer to catch errors.