I just started learning to program and I am watching a tutorial online and do not understand how he is using loops.
This is his example and works
<!DOCTYPE html>
<html>
<head>
<title> Random </title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<div class="container">
</div>
<script>
var numbers = [33,54,76,34,2,6];
numbers.forEach(function(number){
document.write(number);
});
</script>
</body>
</html>
This is mine and doesn't work
<!DOCTYPE html>
<html>
<head>
<title> Random </title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<div class="container">
</div>
<script>
var foods = [pie,cake,brownie];
foods.forEach(function(string){
document.write(string);
});
</script>
</body>
</html>
I have tried replacing the string value in the parenthesis with number but that doesn't work. In the correct code he uses the variable number even though the defined variable is numbers can someone please explain.