JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

Brian Foley
Brian Foley
8,439 Points

My code isn't working :(

Unfortunately I can't figure out why the program doesn't run when I preview the workspace. Here's what it looks like for me:

screenshot

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

Hi there! This may sound silly, but make sure you've saved your file. In the picture provide here, the file isn't saved as denoted by the orange circle. If it's still not working, you might try including a snapshot to your workspace so we can look at the entire project. :sparkles:

4 Answers

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! You have an error on this line:

 print( 'Nope, we don't have any ' + search + ', sorry'); 

Because you use an apostrophe inside the string, it believes that the apostrophe in "don't" is actually the end of the string. Try this instead:

 print( "Nope, we don't have any " + search + ', sorry'); 

Hope this helps! :sparkles:

Hi Brian,

You have a problem with your quotes in this line

print( 'Nope, we don't have any ' + search + ', sorry');

You're enclosing the string in single quotes but you also have a literal single quote within your string.

You could either escape the single quote by putting a backslash in front of it

'Nope, we don\'t have any '

Or enclose the string in double quotes so that you don't have to escape single quotes within it.

"Nope, we don't have any "
Brian Foley
Brian Foley
8,439 Points

Thanks Jennifer. It was saved, I just hit the spacebar somewhere before taking the screengrab. Here's the snapshot: https://w.trhou.se/0g3maylssz

Brian Foley
Brian Foley
8,439 Points

Oh man I can't believe I didn't see that. Thanks so much!