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

Amy Tomey
Amy Tomey
9,025 Points

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

Amy Tomey
Amy Tomey
9,025 Points

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