Hello, I am having some trouble while completing the animal facts react project, the project works up until the displayFact function as the fact does not seem to appear when the image is clicked. Thank you in advance for any help!
import { animals } from './animals';
import React from 'react';
import { createRoot} from 'react-dom/client';
const container = document.getElementById('app');
const root = createRoot(container);
const background = (
<img
className='background'
alt='ocean'
src='/images/ocean.jpg'
/>
);
const images = [];
for(const animal in animals){
images.push(
<img
key={animal}
className='animal'
alt={animal}
src={animals[animal].image}
ariaLabel={animal}
role='button'
onClick = {displayFact}
/>
)
};
function displayFact(e){
const animalName = e.target.alt;
const optionIndex = Math.floor(Math.random() * animalName.facts.length);
const funFact = animalName[optionIndex];
document.getElementById('fact').innerHTML= funFact;
}
const title = ''
const animalFacts = (
<div>
<h1>{title === '' ? 'Click an animal for a fun fact' : title}</h1>
{background}
<p id='fact'></p>
<div className='animals'>
{images}
</div>
</div>
);
root.render(animalFacts);