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

My code is not prompting the questions when I run it?

Here is my code because I did not know how to link the WorkSpace Snapshot:

/* 
  1. Store correct answers
   - When quiz begins, no answers are correct
*/
let correctAnswers = 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("What country has the Taj Mahal?");
if(answer1.toUpperCase() === 'INDIA'){
  correctAnswers += 1;
}

const answer2 = prompt("What country has the Angel Falls");
if(answer2.toUpperCase() === 'VENEZUELA'){
  correctAnswers += 1;
}

const answer3 = prompt("What country has the Mount Fuji?");
if(answer3.toUpperCase() === 'JAPAN'){
  correctAnswers += 1;
}

const answer4 = prompt("What country has El Yunque?");
if(answer4.toUpperCase() === 'PUERTO RICO'){
  correctAnswers += 1;
}

const answer5 = prompt("What country has the Eiffel Tower?");
if(answer5.toUpperCase() === 'FRANCE'){
  correctAnswers += 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(correctAnswers === 5){
  rank = 'Gold';
  }
  else if(correctAnswers >=3){
    rank = "Silver";
  }
  else if(correctAnswers >= 1{
    rank = "Bronze";
  }
  else{
    rank = "No Crown" ;
  }


// 6. Output results to the <main> element

main.innerHTML = `
  <h2>You got ${correctAnswers} out of 5 questions correct.</h2>
  <p>Crown earned: <strong>${rank}</strong></p>        `;
Brandon White
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 Points

Hey Erick,

I added formatting to your code for you, but I can’t see why the prompts wouldn’t show to the user when run.

You’re running your code in a browser environment, right (and not Node)?

1 Answer

Cameron Childres
Cameron Childres
11,820 Points

Hey Erick,

Take a look at your else if statement for the bronze rank. You're missing the closing parenthesis on the conditional. Past that, everything is looking good!

You could catch this error pretty quickly by taking a look at the console when you view your page. It will show a syntax error with the name of the file followed by a colon and the line that the error is coming from.