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

Only getting one question correct!

// no of correct answer by the user var answer = 0;

var q1 = prompt("What is the capital of India?"); if( q1.toUpperCase() === "DELHI"){ answer ++; } var q2 = prompt("How do you write webpages?"); if( q1.toUpperCase() === "HTML"){ answer ++; } var q3 = prompt("Who do you love?"); if( q1.toUpperCase() === "GOD"){ answer ++; } var q4 = prompt("What is the capital of UK?"); if( q1.toUpperCase() === "LONDON"){ answer ++; } var q5 = prompt("What is the name of our planet?"); if( q1.toUpperCase() === "EARTH"){ answer ++; }

document.write("You have answered " + answer + " number of questions correctly!")

if( answer === 5){ alert("You got gold!"); } else if (answer >= 3){ alert("You got silver") } else if (answer >=1){ alert("You got bronze") } else{ alert("You didn't win any prize:(") }

// no of correct answer by the user var answer = 0;

var q1 = prompt("What is the capital of India?"); if( q1.toUpperCase() === "DELHI"){ answer ++; } var q2 = prompt("How do you write webpages?"); if( q1.toUpperCase() === "HTML"){ answer ++; } var q3 = prompt("Who do you love?"); if( q1.toUpperCase() === "GOD"){ answer ++; } var q4 = prompt("What is the capital of UK?"); if( q1.toUpperCase() === "LONDON"){ answer ++; } var q5 = prompt("What is the name of our planet?"); if( q1.toUpperCase() === "EARTH"){ answer ++; }

document.write("You have answered " + answer + " number of questions correctly!")

if( answer === 5){ alert("You got gold!"); } else if (answer >= 3){ alert("You got silver") } else if (answer >=1){ alert("You got bronze") } else{ alert("You didn't win any prize:(") }

// no of correct answer by the user 
var answer = 0;

var q1 = prompt("What is the capital of India?"); 
if( q1.toUpperCase() === "DELHI"){ 
  answer ++; //this looks funny
} 
var q2 = prompt("How do you write webpages?"); 
if( q1.toUpperCase() === "HTML"){ //should be q2
  answer ++; // this too
} var q3 = prompt("Who do you love?"); 
if( q1.toUpperCase() === "GOD"){ //q3
  answer ++; 
} var q4 = prompt("What is the capital of UK?"); 
if( q1.toUpperCase() === "LONDON"){ // q4
  answer ++; 
} 
var q5 = prompt("What is the name of our planet?"); 
if( q1.toUpperCase() === "EARTH"){  //q5
  answer ++; }

document.write("You have answered " + answer + " number of questions correctly!")

if( answer === 5){ 
  alert("You got gold!"); 
} else if (answer >= 3){ 
  alert("You got silver") 
} else if (answer >=1){ 
  alert("You got bronze") 
} else{ 
  alert("You didn't win any prize:(");
}

1 Answer

It looks like you didn't update your "if q" variables when you copy and pasted. All of the ifs have q1 in them.

lol. How silly of me! Thanks, now i can sleep