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

Need some feedback on my code

Hi guys,

I took a crack at this challenge, but my code isn't really working the way I want it to. Can someone let me know what I am doing wrong?

//Questions
var question1 = prompt("What year did the civil war begin?");
var question2 = prompt("What year did the civil war end?");
var question3 = prompt("What year did World War 1 begin?");
var question4 = prompt("What year did World War 1 end?");
var question5 = prompt("What year did Germany invade Poland?");

//user entries and scorekeeping
var score = 0;
if (question1 === "1860") {
  score += 1;
}
if (question2 === "1865") {
  score += 2;
}
if (question3 === "1910") {
  score += 3;
}
if (question4 === "1914") {
  score += 4;
}
if (question5 === "1939") {
  score += 5;
}

//player medals
if (score === 5) {
  medal = "Gold";
}
else if (score === 4) {
  medal = "Titanium";
}
else if (score === 3) {
  medal = "Silver";
}
else if (score === 2) {
  medal = "Bronze";
}
else if (score === 1) {
  medal = "Iron";
} else {
  document.write("Better luck next time!");
}

//final score and feedback
document.write("<h2>Congratulations! You got " + score + " correct! You have earned the " + medal + " award!</h2>");

2 Answers

I think you may want to have each if conditional give one additional point, or the score will go up to 15. +=1 will give one point for each correct answer. right now you are giving +1+2+3+4+5 which will return 15.

Hi Paul,

You can add the below and should work. It will add an increment of 1 with every correct answer to the var score.

//user entries and scorekeeping
var score = 0;
if (question1 === "1860") {
 score++;
}
if (question2 === "1865") {
  //score += 2;
    score++; 
}
if (question3 === "1910") {
  score++;
}
if (question4 === "1914") {
      score++; 
}
if (question5 === "1939") {
   score++;

}