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 trialIoana Raluca Darie
3,540 PointsUncaught TypeError: Cannot read property 'toLowerCase' of undefined
Help , why i receive this error ?
2 Answers
elk6
22,916 PointsHi Ioana,
Because you defined search as an empty var on line 2. In the while loop you define:
while ( true) {
search = search.toLowerCase();
But, since search is empty, there is nothing to use the toLowerCase method on.
Elian
jobbol
Full Stack JavaScript Techdegree Student 17,885 PointsWhat you have.
var search;
search = search.toLowerCase();
search = prompt( 'Search for a product in our store. Type "list" to show all the products in the stock and "quit" to exit! ' ) ;
This does.
- You first create search as a variable that points to nothing.
- You try to access nothing's toLowerCase method.
- Crash!
What you need
You need to first set search to your prompt and later convert that to lowercase.
var search;
search = prompt( 'Search for a product in our store. Type "list" to show all the products in the stock and "quit" to exit! '
search = search.toLowerCase();
This will instead.
- Create search.
- Set search equal to a string.
- Access string's
toLowerCase
.
Ioana Raluca Darie
3,540 PointsIoana Raluca Darie
3,540 Pointshttps://w.trhou.se/mhxc1m7yya - my code here