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

stian wilks johansen
stian wilks johansen
11,053 Points

Can somone help me wid a javascript problem?

I dont under stand whats wrong. JavaScript

/// 5 Question

var stats =0;
var Answer1 = prompt("Question1");
if (Answer1.toUpperCase() === "ANSWER3") {
  stats+=1;
}
var Answer2 = prompt("Question2");
if (Answer2.toUpperCase() === "ANSWER2") {
  stats+=1;
}
var Answer3 = prompt("Question3");
if (Answer3.toUpperCase() === "ANSWER3") {
  stats+=1;
}
var Answer4 = prompt("Question4");
if (Answer4.toUpperCase() === "ANSWER4") {
  stats+=1;
}
var Answer5 = prompt("Question5");
if (Answer5.toUpperCase() === "ANSWER5") {
  stats+=1;
}

/// rank



if ( stats ===5 ); { 
  alert("5");
} else if ( stats >= 3 ); {
  alert("3-4");
} else if ( stats >= 1 ); {
  alert("1-2");
} else ( stats === 0 ); {
  alert("0");
}
var stats =0; 
var Answer1 = prompt("Question1"); 
if (Answer1.toUpperCase() === "ANSWER3") {
 stats+=1;
 } 
var Answer2 = prompt("Question2"); 
if (Answer2.toUpperCase() === "ANSWER2") {
 stats+=1; 
} 
var Answer3 = prompt("Question3"); 
if (Answer3.toUpperCase() === "ANSWER3") { 
stats+=1; 
}
 var Answer4 = prompt("Question4");
 if (Answer4.toUpperCase() === "ANSWER4") { 
stats+=1; 
} 
var Answer5 = prompt("Question5");
 if (Answer5.toUpperCase() === "ANSWER5") {
 stats+=1;
}

//why you are using semicolon after every if statement below 

if ( stats ===5 ); { 
alert("5"); 
} else if ( stats >= 3 ); {
 alert("3-4");
 } else if ( stats >= 1 ); { 
alert("1-2");
 } else ( stats === 0 ); { 
alert("0");
 }

2 Answers

Remember that syntax is akin to grammer and each coding language has it's own. If memory serves me correctly coding syntax includes everything from actual words to punctuation. In this case you have too many semi-colons and the extras are in the wrong place. When I ran your code and read the console, on the right side of the console was the line of code that was having issues. I would look at where you put the semi-colons and check to see if they are in the right place.

Nathan Wakefield
Nathan Wakefield
7,065 Points

One issue is that your ending else block has a conditional in it. The last else block is what runs if none of the other conditions were true. The last block should look like this:

} else {
  alert("0");
}

And if you wanted to remind yourself what the default condition was, you could write a comment to go with it:

} else  { // stats === 0
  alert("0");
}

But also, the conditionals shouldn't have a semicolon after them. So this:

} else if ( stats >= 1 ); {
  alert("1-2");
}

becomes this:

} else ( stats >= 1 ) { // Note the lack of a semicolon here
  alert("1-2");
}