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

Bartlomiej Pajak
Bartlomiej Pajak
5,062 Points

My solution

Hello, it would be nice to hearing some feedback of you guys!

var score = 0;

var question1 = prompt("What is the name of CEO SpeceX?");
if ( question1.toLocaleUpperCase() === "ELON MUSK" ) {
  score += 1;
}

var question2 = prompt("What is the name of main character from 'The Witcher' ?");
if ( question2.toLocaleUpperCase() === "GERALT" ) {
  score += 1;
}

var question3 = prompt("What is the name of King of the Mordor?");
if ( question3.toLocaleUpperCase() === "SAURON" ) {
  score += 1;
}

var question4 = prompt("What is the surname of the most popular Jedi in 'Star Wars'?");
if ( question4.toLocaleUpperCase() === "SKYWALKER" ) {
  score += 1;
}

var question5 = prompt("What is the name of Lord of The Rings author?");
if ( question5.toLocaleUpperCase() === "TOLKIEN" ) {
  score += 1;
}

if ( score === 5 ) {
  alert(`You answered ${score} question and earned gold crown!`);
} else if ( score === 3 || score === 4) {
  alert(`You answered ${score} question and earned silver crown!`);
} else if ( score === 2 || score === 1 ) {
  alert(`You answered ${score} question and earned bronze crown!`);
} else {
  alert(`You answered ${score} question. Better luck next time!`);
}

1 Answer

If you did not do the functions and loops courses, then it is quite good but otherwise, you could have made a function like ask question or verify question.