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

Reza Zandi
Reza Zandi
Full Stack JavaScript Techdegree Student 1,599 Points

Here's my code, any suggestions?

// Keep ing track of questions answered correctly
var numberQuestionsAnwseredCorrectly = 0

var quiz = alert("It is time to begin the quiz! You will be asked 5 random trivia questions. Depending on how many you answer correctly, you will receive a Gold, Silver, or Bronze crown or no crown at all if you get 0 correct. Good luck! May the gods be in your favor!");

// list of trivia questions
var question1 = prompt("How many Oscars has Leonardo Dicapio won?");
var question2 = prompt("Who was the best quarterback in Colts history");
var question3 = prompt("In what year did former president Barrack Obama get elected?");
var question4 = prompt("How many presidents came before Trump?");
var question5 = prompt("Who won the last Superbowl?");

// if statements for prompts/questions , and adds points to the variable tracking it so we know how many they got right
if (question1 === '1' || question1 === 'one'){ numberQuestionsAnwseredCorrectly += 1};
if (question2.toUpperCase() === 'PEYTON MANNING'){numberQuestionsAnwseredCorrectly += 1};
if (question3 === '2008'){ numberQuestionsAnwseredCorrectly += 1};
if (question4 === '44') {numberQuestionsAnwseredCorrectly += 1};
if (question5.toUpperCase() === 'NEW ENGLAND PATRIOTS' || question5.toUpperCase() === 'PATRIOTS' || question5.toUpperCase() === 'NEW ENGLAND'){
  numberQuestionsAnwseredCorrectly += 1};

// if, else if, else clause to determine the rank of the player based on anwsers 

if (numberQuestionsAnwseredCorrectly > 4){document.write("<h1>You answered all questions 5 correct, you earn the Gold Crown!</h1>")}
    else if (numberQuestionsAnwseredCorrectly > 2){document.write("<h1>You answered " + numberQuestionsAnwseredCorrectly + " out of 5 questions correct, you earn the Silver Crown!</h1>")}
    else if (numberQuestionsAnwseredCorrectly > 0){document.write("<h1>You answered " + numberQuestionsAnwseredCorrectly + " out of 5 questions correct, you earn the Bronze Crown!</h1>")}
    else {document.write("<h1> You anwsered 0 out of 5 questions correct, you earn no crown. Go study up and come back!</h1>")};
Steven Parker
Steven Parker
229,644 Points

This seems to be a duplicate of this other question. Look for the answer(s) left there.

You might want to delete this one. Click the small rectangle with the 3 dots in it to reveal the delete option. Note that this can only be done while the question has no answers.