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

Raul Vega
PLUS
Raul Vega
Courses Plus Student 3,803 Points

My solution (Feedback)

I tried to make a simple yes or no quiz and define a trophy for each score, any feedback appreciated.

/*
Random Geo Quiz
*/
alert("Welcome to The Ultimate Quiz, type [y]es or [n]o to answer.");

var correctAnswers = 0;
var firstQuestion = prompt("Is Tokyo located in China?");
  if(firstQuestion.toUpperCase() === "N" || firstQuestion.toUpperCase() === "NO"){
   correctAnswers+=1;
  }
var secondQuestion = prompt("Is Cuba in the Pacific Ocean?");
  if(secondQuestion.toUpperCase() === "N" || secondQuestion.toUpperCase() === "NO"){
   correctAnswers+=1;
  }
var thirdQuestion = prompt("Is Canada in the northern hemisphere?");
  if(thirdQuestion.toUpperCase() === "Y" || thirdQuestion.toUpperCase() === "YES"){
   correctAnswers+=1;
  }
var fourthQuestion = prompt("Is Puerto Rico in the Caribbean Sea?");
  if(fourthQuestion.toUpperCase() === "Y" || fourthQuestion.toUpperCase() === "YES"){
   correctAnswers+=1;
  }
var fifthQuestion = prompt("Is Germany in Asia?");
  if(fifthQuestion.toUpperCase() === "N" || fifthQuestion.toUpperCase() === "NO"){
   correctAnswers+=1;
  }

//Define a trophy for each score
var trophyMaterial;
if(correctAnswers === 5){
  trophyMaterial = "platinum";
}else if(correctAnswers === 4){
  trophyMaterial = "gold";
}else if(correctAnswers === 3){
  trophyMaterial = "silver";
}else if(correctAnswers === 2){
  trophyMaterial = "bronze";
}else if(correctAnswers === 1){
  trophyMaterial = "plastic";
}else{
  trophyMaterial = "none";
}

document.write("<h3>Thanks for playing!</h3>");
if(correctAnswers > 0){
document.write("<h3>You got the " + trophyMaterial + " trophy.</h3>");
}else{
document.write("<h3>You got no trophy, better luck next time.</h3>");
}
document.write("<i>You answered " + correctAnswers + " out of 5 questions correctly.</i>");
Matthew Rigdon
Matthew Rigdon
8,223 Points

The code is very clean. Looks good to me!

2 Answers

Looks great! I love the comments!