Can anyone help explain to me why the below function works but the one commented out doesn’t work? Is there a syntax error I’m missing?
// const displayFact = (e) => {
// const selectedAnimal = e.target.alt;
// const animalInfo = animals[selectedAnimal]
// const optionIndex = Math.floor(Math.random()*animalInfo.facts.length);
// const fact = animalInfo.facts[optionIndex];
// document.getElementById('fact').innerHTML = fact;
// }
function displayFact(e){
const selectedAnimal = e.target.alt;
const animalInfo = animals[selectedAnimal]
const optionIndex = Math.floor(Math.random()*animalInfo.facts.length);
const fact = animalInfo.facts[optionIndex];
document.getElementById('fact').innerHTML = fact;
}