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

Shade Webb
Shade Webb
1,601 Points

Why doesn't this work?

// score is 0 to start
var score = 0;

// first question
var questionOne = prompt("Does a Boolean have true and false values?");

console.log(questionOne);

// update score
if (questionOne.toUpperCase === "YES") {
  score += 1;
}

console.log(score);

The above code refuses to update the score past 0 when any form of "yes" "YES" or "Yes" is entered into the prompt. I'm completely lost.

There are no syntax errors, and the code is incredibly simple. Ask a question, get a "yes", turn it into "YES", if the answer is "YES" then update the score variable by 1 from it's previous amount.

2 Answers

Shade Webb
Shade Webb
1,601 Points

I figured it out by checking MDN like I should have done in the first place! The .toUpperCase method requires () to be placed after it, making it .toUpperCase() for it to work.

Why does this not cause in error in the JS environment? Who knows.

Alfredo Gayou
Alfredo Gayou
7,051 Points

just to add, all methods have parenthesis. properties dont

calling questionOne.toUpperCase without parenthesis will return the function definition of "toUpperCase" ! that been said now this is how "if" will treat your statement? if (questionOne.toUpperCase === "YES") if ("function() { function definition of to upperCase }" === "YES") now we're comparing two different strings so if will return false :)