var userInput = prompt('Select a fruit:');
var fruitList = ["apple", 'grapes', "orange"];
for(var i=0; i<fruitList.length; i++);
if(userInput == fruitList[i]){
alert("Apologies, we are currently out of " + userInput);
}else{
var userFruit = document.createElement('li');
userFruit.textContent = userInput;
var fruits = document.getElementById('list');
fruits.appendChild(userFruit);
}
<div id="list"></div>
The issue seems to be with the for loop as it is adding the user input to the list without recognizing elements from the array. The list (not included here) has id="list"
and contains three elements from the array. Thank you!
var userInput = prompt('Select a fruit:');
var fruitList = ["apple", 'grapes', "orange"];
for(var i=0;i<fruitList.length; i++);
if(userInput == fruitList[i]){
alert("Apologies, we are currently out of " + userInput);
}else{
var userFruit = document.createElement('li');
userFruit.textContent = userInput;
var fruits = document.getElementById('list');
fruits.appendChild(userFruit);
}