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. :\