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

I can't figure out what I'm doing wrong...

var questionOne = prompt("What color is the ocean?"); // blue
var questionTwo = prompt("What color is the grass?"); // green
var questionThree = prompt ("What color is the sand?"); // yellow
var questionFour = prompt("What color is the mountain?"); // green
var questionFive = prompt("What color is OJ?"); // orange
var score = 0;

if (questionOne.toUpperCase === "BLUE") {
  score += 1;
}

if (questionTwo.toUpperCase === "GREEN") {
  score += 1;
}

if (questionThree.toUpperCase === "YELLOW") {
  score += 1;
}

if (questionFour.toUpperCase === "GREEN"); {
  score += 1;
}

if (questionFive.toUpperCase === "ORANGE") {
  score += 1;
} 

document.write("Congrats, you got " + score + " questions correct!");

if (score === 5) {
  document.write("You got a GOLD crown!");
} else if (score === 3 || score === 4);
  document.write("You got a silver crown.");
} else if (score === 1 || score === 2);
  document.write("You got a bronze crown.");
} else {
  document.write("Sorry no crown.")
}

2 Answers

Grace Kelly
Grace Kelly
33,990 Points

Hi Yuka, you're code is perfect except for some very slight syntax errors here:

if (score === 5) {
  document.write("You got a GOLD crown!");
} else if (score === 3 || score === 4); //syntax error here
  document.write("You got a silver crown.");
} else if (score === 1 || score === 2); //syntax error here
  document.write("You got a bronze crown."); 
} else {
  document.write("Sorry no crown.")
}

You simply need to replace the semi-colans with opening curly brackets to declare the conditional statements, as you did correctly with your first if statement, like so:

if (score === 5) {
  document.write("You got a GOLD crown!");
} else if (score === 3 || score === 4) { //change ; to {
  document.write("You got a silver crown.");
} else if (score === 1 || score === 2){ //change ; to {
  document.write("You got a bronze crown.");
} else {
  document.write("Sorry no crown.")
}

Hope that helps!!

The only thing I would add is to remember to put "()" after the toUpperCase method like so: .toUpperCase()

Grace Kelly
Grace Kelly
33,990 Points

Ahh I didn't notice that as the code was working without them but yes Jacob's right toUpperCase() is the proper syntax :)

YESSSS! That worked - thank you both!!