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 Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

slava vissoki
PLUS
slava vissoki
Courses Plus Student 1,709 Points

search===null , is not solving the error by the console, why?

while(true) { search = prompt('please type your name'); if(search.toLowerCase() === null || search === 'quit' ){ break; }

still showing: cannot read property tollowercase of null

3 Answers

Cody Te Awa
Cody Te Awa
8,820 Points

Hi Slava, Your problem here is that you are trying to test of the variable 'search' is null however in the same condition you are trying to convert the value inside the variable to lowercase

if (search.toLowerCase() === null)

The problem here is that if the value is equal to null then there is no such method you can call on a null value. So to solve your problem you more or less just want to move the method to the other condition in your if statement. Like this:

while(true) { 
    search = prompt('please type your name'); 
    if(search === null || search.toLowerCase() === 'quit' ) { 
        break; 
    }
}

Keep in mind that if you type nothing in the prompt box and type enter it won't exit because null and an empty string are two different things! Keep up the great work though Slava and happy coding :)

slava vissoki
PLUS
slava vissoki
Courses Plus Student 1,709 Points

thank you for the answer, but i have changed the order of the "tolowercase()" method as you mentioned and it is still showing me the same error, why?

while(true) { search = prompt('please type your name'); if(search.toLowerCase() === 'quit' || search === null ){ break; }

Cody Te Awa
Cody Te Awa
8,820 Points

Hi Slava, it looks great now the only thing you want to do is swap the ordering of the condition to this:

if(search === null || search.toLowerCase() === 'quit' )

The reason being that is because if the value of search is null it is still trying to convert it to lower case before it checks it is null. But in the way shown above it checks if it is null before continuing on to check if the value is quit :) Note: It also appears as though you are missing a closing brace of the while loop in the code you supplied. Happy coding Slava! :)