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

my prompt comes up perfectly, then i get an error... i can't see what I'm missing.

When i input anything into the prompt, nothing happens. I get the following error on the console: Uncaught ReferenceError: documant is not defined at search-list.js:11 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;

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

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

You made several syntax mistakes.

Here is the full HTML code for what you want:

<!DOCTYPE html>
<html>
<body>
  <p id = "main"></p> 
  <script>
 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;

  if (inStock.includes(search))
     { 
        message = `Yes, we have <strong>${search}</strong>.`

     }
     else 
     { 
        message = `Sorry, we do not have <strong>${search}</strong>.`

     }

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

</body>

</html>

2 Answers

Just use the JavaScript code I put inside the "<script>" tags

Thank you for the HTML answer, but I am working on a javascript challenge. I apologize for not making my question more specific.