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

Richard Verbraak
Richard Verbraak
7,739 Points

Off-Topic: Why won't search.toUpperCase === "Quit" work here?

Title.

I figured I'd implement the toUpperCase method for fun, it somehow doesn't work in this code though, how so?

In my understanding it would change the user input in the prompt to all uppercase letters, in this case, to "QUIT". And make "QUIT" === "QUIT" so it would be pass regardless of typing it in lowercase or uppercase.

i.e.

while (true) { search = prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit"); if (search.toUpperCase === "QUIT") { break; } }

Hey Richard, I think you need the parentheses after .toUpperCase to make it a function call.

(search.toUpperCase() === "QUIT") { break; }

1 Answer

Emmanuel C
Emmanuel C
10,636 Points

Hey Richard,

toUpperCase is a function so it should have parenthesis at the end of it. Else it would be treated as a property, and since none exist itll throw an error. Try...

while (true) { 
    search = prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit"); 
    if (search.toUpperCase() === "QUIT") { 
        break; 
    } 
}
Richard Verbraak
Richard Verbraak
7,739 Points

Ahhh of course! Completely forgot to add the parenthesis..

Thanks.