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

can someone check this code from the conditional challenge please !

I have created this quiz for capitals , it may not be the shortest way but this is what I could think of . it is not executing . not even the prompt dialog.

https://w.trhou.se/0uogw6lbxa

5 Answers

Erik Nuber
Erik Nuber
20,629 Points

Looking at your code, you need to change all score marks to either

score +=1

score += 0

using score === 0 isn't doing anything on it's own. This would be used to make a comparison in a conditional statement.

if (score === 0) {

} else {

}

If you just did score = 0 then you are resetting score to 0 everytime someone gets a question wrong so you would need to either do nothing with score or set it to score += 0

By using

score +=1

score += 0

You are in effect saying score = 1 + 1 + 0 + 1 + 0

Erik Nuber
Erik Nuber
20,629 Points

Here is the code a bit cleaned up, the rest would follow the same way. You could be checking for "" but, at this point in the lessons, I don't believe that is necessary.

Also, just FYI the capital of the US is Washington DC.

var score = 0;
var q1 = prompt("what is the capital of India?");

if (q1.toUpperCase() === "NEW DELHI"){
  alert('right');
  score += 1;
} else {
    alert('wrong');
     score += 0;
  }

ya was too keen on seeing the code run than the info I was putting there. thanks anyways !

even after fixing the score variable the prompt box wont appear. does not look like it is executing at all.

Erik Nuber
Erik Nuber
20,629 Points
var score = 0;
var q1 = prompt("what is the capital of India?");

if (q1.toUpperCase() === "NEW DELHI"){
  alert('right');
  score += 1;
} else {
    alert('wrong');
     score === 0;
  }

var q2 = prompt("what is the capital of USA?");
if (q2.toUpperCase() === "Washington DC"){
  alert('right');
  score += 1;
} else {
    alert('wrong');
     score === 0;
  }

document.write("You got a score of "  + score + " points");

.