JavaScript JavaScript Arrays Loop Through Arrays Search for a Value in an Array

Console Error for ${message}

Here is my code:

const inStock = ['pizza', 'cookies', 'eggs', 'apples', 'milk', 'cheese', 'bread', 'lettuce', 'carrots', 'broccoli', 'potatoes', 'crackers', 'onions', 'tofu', 'limes', 'cucumbers'];
const search = prompt('Search for a product.');
let message;

message=`<b><u>${search}</u></b> is in stock!`;
} else {
 message=`<b><u>${search}</u></b> is out of stock!`; 

document.querySelector('main').innerHTML= ${message};

When I replace ${message} by message, it works.

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, Terence Fong! I went ahead and added some markdown to your question so that it renders correctly. It looks like you forgot a pair of backticks around the {$message}. You said your code looks like this:

document.querySelector('main').innerHTML= ${message};

But that should be:

document.querySelector('main').innerHTML= `${message}`;

Note the backticks around the ${message}

Hope this helps! :sparkles: