Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge

Two issues I'm having trouble fixing (It's listed in the comments). I just listed the code should u need it.

//This initiates the program.

console.log("Begin program");

//An introduction alert that pops up at the start.

alert("Howdy newcomers! In this quick quiz, you wil be testing your knowledge on some basic historical knowledge! So stick to it and don't give up! Click ok to continue.");

/*This section is where I give questions, answer, scoring reward system different variables, and apply those variables to the necessary if, if else declarations. Additionally, I also added a "second chance" for the user to answer the question again. Various point variables are to tally the score up as the user progresses through the quiz.*/

var answer1 = ("HIROSHIMA AND NAGASAKI");
var answer2 = ("US FOUNDING FATHER AND GENERAL");
var answer3 = ("ULANBATAAR");
var answer4 = ("LOUIS XIV");
var answer5 = ("VON HABSBURG");
var points = 0;
var goldCrown = ("Congratulations! You achieved total victory!");
var silverCrown = ("So close, yet no cigar!");
var bronzeCrown = ("Good try! Your on the right track!");
var noCrown = ("Better luck next time!");
var questionOne = prompt("What were the two cites that had an atomic bomb dropped on, during World War Two called?");
  if (questionOne.toUpperCase() === answer1)
     {points += 1;
      alert("Correct! You have completed one of five questions. You have a score of: " + points + ". Press ok to continue.");}
  else
     {alert("Sorry, that is not correct. Moving on.");}
var questionTwo = prompt("Who was George Washington?");
  if (questionTwo.toUpperCase() === answer2)
     {points += 1;
      alert("Correct! You have completed two of five questions. You have a score of: " + points + ". Press ok to continue.");}
  else
     {alert("Sorry, that is not correct. Moving on.");}
var questionThree = prompt("What is the capitol of Mongolia?");
  if (questionThree.toUpperCase() === answer3)
     {points += 1;
      alert("Correct! You have completed three of five questions. You have a score of: " + points + ". Press ok to continue.");}
  else
     {alert("Sorry, that is not correct. Moving on.");}
var questionFour = prompt("Which monarch was widely became known as The Sun King?");
  if (questionFour.toUpperCase() === answer4)
     {points += 1;
      alert("Correct! You have completed four of five questions. You have a score of: " + points + ". Press ok to continue.");}
  else
     {alert("Sorry, that is not correct. Moving on.");}
var questionFive = prompt("Beside the Carolingian dynasty, which other European dynasty came closest to a unified Europe?");
  if (questionFive.toUpperCase() === answer5)
     {points += 1;
      alert("Correct! You have completed five of five questions. You have a score of: " + points + ". Press ok to continue.");}
  else
     {alert("Sorry, that is not correct. Moving on.");}

/*This is the reward system I setup:
-----> Gold Crown: 5 points
-----> Silver Crown: 3 - 4 points
-----> Bronze Crown: 2 points
-----> No Crown: 0 points
*/

  if (points === 5)
    {document.write (goldenCrown + " With a score of " + points + ", you have been awarded the Gold Crown.");}
  else if (points === 3 || points === 4) 
    {document.write (silverCrown + " With a score of " + points + ", you have been awarded the Silver Crown.");}
  else if (points === 1 || points === 2)
    {document.write (bronzeCrown + " With a score of " + points + ", you have been awarded the Bronze Crown.");}
  else if (points === 0) 
    {document.write (noCrown + " With a score of " + points + ", you will not be awarded anything.");}
  else
    {document.write ("Hope you had fun! See you around next time!")}

//This declarattion ends the program.  

console.log("End program");

(a) Whenever I get all questions right and rack up five points, it doesn't display anything. As far as I know it's written precisely.

(b) In the "else" statement at the end of the reward system with the message won't display either as an alert or to the document.

So...unless I'm missing something, I'm not quite seeing it

2 Answers

answer to (a):

you have var defined as goldCrown and then called as goldenCrown in:

if (points === 5)
    {document.write (goldenCrown + " With a score of " + points + ", you have been awarded the Gold Crown.");}

correct this to match one or the other

answer to (b):

you dont' need the "else" statement you can write it as:

document.write ("<br>Hope you had fun! See you around next time!");

since javaScript reads top to bottom it will automatically go to this line regardless of the outcome of the if else statements

Thank you so much! Works perfectly now.

Glad to hear it's working!