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

How's this for a first attempt?

/* 
Asks five questions then
ranks players based on score
*/

//Assigns score value to 0.

var score = 0;

//Asks the questions and increases the score if the answers were correct.

var questionOne = prompt("What is the capital of England?");
if (questionOne.toLowerCase() === "london") {
  score += 1;
  alert("Correct!");
} else {
  alert("Wrong!");
}

var questionTwo = prompt("What language is this code written in?");
if (questionTwo.toLowerCase() === "javascript") {
  score += 1;
  alert("Correct!");
} else {
  alert("Wrong!");
}

var questionThree = prompt("Who is the Goddess of Chaos in Greek Mythology?");
if (questionThree.toLowerCase() === "eris") {
  score += 1;
  alert("Correct!");
} else {
  alert("Wrong!");
}


var questionFour = prompt("Where did I learn how to do this?");
if (questionFour.toLowerCase() === "treehouse") {
  score += 1;
  alert("Correct!");
} else {
  alert("Wrong!");
}


var questionFive = prompt("What did the fish say when he hit his head against a wall?");
if (questionFive.toLowerCase() === "dam" || questionFive.toLowerCase() === "damn") {
  score += 1;
  alert("Correct!");
} else {
  alert("Wrong!");
}


//Provides the user with final results

if (score === 0) {
  alert("You answered " + score + "right. You failed to win a crown!");
} else if (score === 1 || score === 2) {
  alert("You answered " + score + " right. You won a bronze crown!");
} else if (score === 3 || score === 4) {
  alert("You answered " + score + " right. You won a silver crown!");
} else if (score === 5) {
  alert("You answered " + score + " right. You won a gold crown!");
} else {
  alert("Something went wrong. Either I suck or you suck!");
}

1 Answer