Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,035 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.