Hi everyone!
I’m struggling with Animal Fun Facts challenge. I did everything for “We should see a fact pop up on the screen!” But, it’s not
Can somebody please tell me what went wrong? I’ve researched Forum and checked the Unstuck video - still didn’t help.
import { animals } from './animals';
//import the React and ReactDOM libraries
import React from 'react';
import ReactDOM from 'react-dom';
const title = "";
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 selectedAnimal = e.target.alt;
const animalInfo = animals[selectedAnimal];
const optionIndex = Math.floor(Math.random() * animalInfo.facts.length);
const funFacts = animalInfo.facts[optionIndex];
document.getElementById('fact').innerHTML = funFacts;
}
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>
);
ReactDOM.render(animalFacts,
document.getElementById("root"));