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

Chetan Shah
Chetan Shah
649 Points

Whats wrong in these type of comparison? How to correct?

if (parseInt(answers) === 5 ){ document.write('you won gold'); }

if (parseInt(answers) === 4 || 3 ){ document.write('you won silver'); }

if (parseInt(answers) === 2 || 1 ){ document.write('you won bronze'); }

5 Answers

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points
// when using && or || you need to do it like this
if (parseInt(answers) === 4 || parseInt(answers) === 3 ) { // notice the difference in this line :-)
  document.write('you won silver'); 
}
Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

You don't need to use parseInt(answers) because you know it's an integer.

// else statements don't take arguments/conditions
else {
  document.write("None");
}
Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points
var answers = 0;

var questionOne = prompt("What is the capital of India?"); 
if (questionOne.toUpperCase() === 'DELHI') { 
  answers += 1; 
}

var questionTwo = prompt("What is the national animal of India?"); 
if (questionTwo.toUpperCase() === 'TIGER') { 
  answers += 1;
}

var questionThree = prompt("Who is the PM of India?"); 
if (questionThree.toUpperCase() === 'NARENDRA MODI') { 
  answers += 1;
}

var questionFour = prompt("What is the national game of India?"); 
if (questionFour.toUpperCase() === 'HOCKEY') { 
  answers += 1;
}

var questionFive = prompt("Name of your country?"); 
if (questionFive.toUpperCase() === 'INDIA') { 
  answers += 1;
} 

// Example output:
// Answers correct: 3
// Silver 
document.write('Answers correct: ' + answers + '\n'); 

if (answers === 5) { 
  document.write("Gold"); 
} else if (answers === 4 || answers === 3 ) { 
  document.write ("Silver");
} else { 
  document.write("None");
}
Chetan Shah
Chetan Shah
649 Points

THIS IS NOT WORKING

var answers = 0;

var questionOne = prompt("What is the capital of India?"); if (questionOne.toUpperCase() === 'DELHI'){ answers+=1; }

var questionTwo = prompt("What is the national animal of India?"); if (questionTwo.toUpperCase() === 'TIGER'){ answers+=1;

}

var questionThree = prompt("Who is the PM of India?"); if (questionThree.toUpperCase() === 'NARENDRA MODI'){ answers+=1;

}

var questionFour = prompt("What is the national game of India?"); if (questionFour.toUpperCase() === 'HOCKEY'){ answers+=1;

}

var questionFive = prompt("Name of your country?"); if (questionFive.toUpperCase() === 'INDIA'){ answers+=1;

} document.write('Answers correct\n '+answers);

if (parseInt(answers) === 5){ document.write("Gold"); } else if(parseInt(answers) === 4 || parseInt(answers) === 3 ){ document.write ("Silver");}

else(parseInt(answers === 2) || parseInt(answers === 1)){ document.write("None");}

Chetan Shah
Chetan Shah
649 Points

How should i bring output on nextline?

Answers correct 4Silver

This is what i am getting.