<!doctype html>
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8">
<script>
var foodItem0 = prompt("Enter your favorite food");
var foodItem1 = prompt("Enter your second favorite food");
var foodItem2 = prompt("Enter your third favorite food");
var allFood = [foodItem0,foodItem1,foodItem2];
function favoritefood(){
for(x=0;x>allFood.length;x++){
var id="item"+x;
var li=document.getElementById(id);
li.innerHTML=allFood[x];
}
}
window.onload=favoritefood;
</script>
</head>
<body>
<h1>Top Three Favorite Food Items</h1>
<ol>
<li id="item0"></li>
<li id="item1"></li>
<li id="item3"></li>
</ol>
</body>
</html>
If i am allowed to declare the array "allfood" like that please explain why the code is not working the list numbers are showing up but not the food that i enter in the prompts
document.getElementById("item2")returnsnull. Your ids should beitem0,item1,item2.for(x=0;x < allFood.length;x++){.<not>