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

Nekki(Eno) Jose
seal-mask
.a{fill-rule:evenodd;}techdegree
Nekki(Eno) Jose
Full Stack JavaScript Techdegree Student 796 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
}