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 Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Sam Wolf
seal-mask
.a{fill-rule:evenodd;}techdegree
Sam Wolf
Full Stack JavaScript Techdegree Student 1,039 Points

Score is not adding up correctly

No matter what my answers are, my score comes out to 0 every time and the Crown color is Silver. Any advice is appreciated. Thank you!

let score = 0;
let color = 0;
const firanswer = prompt('What color is the sky?');
if (firanswer.toUpperCase === 'BLUE'){
    score += 1;}

const secanswer = prompt('What color are leaves?');
if (secanswer.toUpperCase === 'GREEN'){
    score += 1;}

const thianswer = prompt('What is my name?');
if (thianswer.toUpperCase === 'SAM'){
    score += 1;}

const foranswer = prompt('What color is snow?');
if (foranswer.toUpperCase === 'WHITE'){
    score += 1;}

const fifanswer = prompt('What state am I in?');
if (fifanswer.toUpperCase === 'ARKANSAS'){
    score += 1;}

if (score === 5){
  (color = 'Gold');
} else if (score => 3){
  (color = 'Silver');
} else if (score =>1){
  (color = 'Bronze');
} else {
  (color = 'No Crown');}

const message = `<h2>You got ${score} out of 5 questions correct</h> 
<p>Crown earned ${color}</p>`;
document.querySelector('main').innerHTML = message;

3 Answers

Hi Sam Wolf

The scores are not adding because you are missing the parentheses of toUpperCase.

It should be:

.toUpperCase()
Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Sam Wolf! It's the result of two simple typos :smiley: You're not far to having this working like you want.

You typed:

} else if (score => 3){
  (color = 'Silver');
} else if (score =>1){

But the equals and the > are backwards. When saying "Greater than or equal to", the greater than sign comes first and the equals comes second. You meant to type:

} else if (score >= 3){  // switched the > and =
  (color = 'Silver');
} else if (score >= 1){  // switched the > and =

Hope this helps! :sparkles:

Hi Sam, One thing you should also change along with Jennifer's suggestions would be to add parenthesis "()" after your toUpperCase method calls. Because of that typo, the "if" conditionals can never evaluate to true because of the invalid method call and your score variable will never increment.