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

Nekki(Eno) Jose
seal-mask
.a{fill-rule:evenodd;}techdegree
Nekki(Eno) Jose
Full Stack JavaScript Techdegree Student 1,951 Points

toUpperCase() is not working ? JavaScript Quiz challenge

So I was working on the JavaScrip Quiz challenge in Unit 1 I did not really have a major problem and I was able to solve my own problem but I just got curious So here is what my conditional statement looks like

const questionOne = prompt("Are you learning JavaScript?");

if ( questionOne === "yes" || questionOne === "Yes") {
correctAnswers += 1
}

I used the OR operator but I originally wanted to use the property ".toUpperCase()" to provide flexibility to my answers e.g:

const questionOne = prompt("Are you learning JavaScript?");

if ( questionOne.toUpperCase() === "Yes" ) {
correctAnswers += 1
}

My answer for this is either Yes or yes. Capitalized or not it should work. From the Mercury example, I thought this approach would work, however, no matter what I do, I cannot get the point for this question. And when I check using google dev tools by console logging console.log(questionOne) I get 0 points instead of 1

I have tried experimenting with it by having yes lower cased and upper cased but nothing seems to work... if ( questionOne.toUpperCase() === "yes" ) or if ( questionOne.toUpperCase() === "Yes" )

Any reason why I am having this problem?

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hi Nekki(Eno) Jose 👋

The .toUpperCase() method makes the entire string uppercased. If you want it to become true you'll want to compare your questionOne.toUpperCase() to an all uppercase YES.

const questionOne = prompt("Are you learning JavaScript?");

if ( questionOne.toUpperCase() === "YES" ) {
correctAnswers += 1
}