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

Richard Verbraak
Richard Verbraak
7,726 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,635 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,726 Points

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

Thanks.