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 Arrays Loop Through Arrays Search for a Value in an Array

Andy Hetherington
Andy Hetherington
2,400 Points

How can I get the message to display on the page. Despite checking through twice I cannot see were I have gone wrong.

here is my code

if ( instock.includes(search) ) { message = Yes, we have <strong>${search}</strong>.; } else { message = Sorry, we do not have <strong>${search}</strong>.; }

document.querySelector('main').innerHTML = <p>${message}</p>;

2 Answers

Andy Hetherington
Andy Hetherington
2,400 Points

Ok, I see I missed a capital at inStock.

Hey Andy,

I hope you got this figured out. In case you didn't, I just wanted to let you know something else I noticed in your code. It looks like you didn't enclose the contents of the message variable in backticks ``. That would also cause some issues.

Hope this helps anyone who may have this issue in the future. :) Happy coding!

I definitely helped me. I couldn't figure out why my code looked exact but wouldn't work and returned ${message} on the screen. I wasn't using backticks. :\