I'm fiddling around with JS and made a random word generator (foodinator) for practicing purposes. How can I implement images with this? Dish 1 should always show with Image 1, Dish 2 with Image 2 and so on.
HTML (index.html)
<div class="wrapper">
<div class="title">
<h1><u>What are you going to eat?</u></h1>
</div>
<div id="foodDisplay">
</div>
<div class="button">
<button onclick="newFood()">
New Dish!
</button>
</div>
</div>
JavaScript (scripts.js)
var foods = [
'Dish 1',
'Dish 2',
'Dish 3',
'Dish 4',
'Dish 5',
'Dish 6',
'Dish 7',
'Dish 8',
'Dish 9',
'Dish 10'
];
function newFood() {
var randomNumber = Math.floor(Math.random() * (foods.length));
document.getElementById('foodDisplay').innerHTML = foods[randomNumber];
}
When clicking the button it picks a random dish from the list, that works. I expect it to show up with the correct image. I know it is very basic knowledge, I hope some one can direct me in the right direction. Thanks in advance.