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 Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Pedro Huertas
Pedro Huertas
3,047 Points

Can someone please let me know why I don't see any output from this?

This is my code

  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');

/*
  4. Ask at least 5 questions
   - Store each answer in a variable
   - Keep track of the number of correct answers
*/
const answer1 = prompt("Name a programming language that's also a gem.");
if ( answer1.toUpperCase() === 'RUBY' ){
  correct += 1;
}
const answer2 = prompt("Name a programming language that's also a snake.");
if ( answer2.toUpperCase() === 'PYTHON' ){
  correct += 1;
}
const answer3 = prompt("What language do you use to style web pages?");
if ( answer3.toUpperCase() === 'CSS' ){
  correct += 1;
}
const answer4 = prompt("What language do you use to build the structure of web pages?");
if ( answer4.toUpperCase() === 'HTML' ){
  correct += 1;
}
const answer5 = prompt("What language do you to add interactivity to a web page?");
if ( answer5.toUpperCase() === 'JAVASCRIPT' ){
  correct += 1;
}

/*
  5. Rank player based on number of correct answers
   - 5 correct = Gold
   - 3-4 correct = Silver
   - 1-2 correct = Bronze
   - 0 correct = No crown
*/
if ( score === 5 ) {
  rank = "Gold"; 
} else if ( score >= 3 ) {
  rank = "Silver";  
} else if ( score >= 1 ) { // check for 1-2 correct
  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>
`;```

I don't see any output from this. Why?

2 Answers

Hi Pedro, I want to thank you for the great comments in your code that made your program a lot easier to debug! So the thing that is going wrong is that, at the end, when you are checking the conditions in your conditional statements, you are evaluating score and score does not exist. To solve your issue, just change score by correct in your conditional statements and every thing should be fine!

Here is the code:

if ( correct === 5 ) {
  rank = "Gold"; 
} else if ( correct >= 3 ) {
  rank = "Silver";  
} else if ( correct >= 1 ) { // check for 1-2 correct
  rank = "Bronze";  
} else {
  rank = "None :(";
}

If that helped, please mark as best answer to indicate other students your issue is resolved! Happy Coding!

Pedro Huertas
Pedro Huertas
3,047 Points

Thank you, I missed it completely.

Do not worry, we all make mistakes!