How can I create a JavaScript function that displays a random word from a list when a button is clicked and prints it in a heading 3? I would appreciate a quick response.
//Start of Js code
let display = document.getElementById("motivato");
console.log(display)
var motivation = [{
quote: "Planting popcorn does not produce more popcorn",
person: "Farmer Ted"
}, {
quote: "White whale, bad whale",
person: "Confucious (Moby Dick)"
}, {
quote: "Use the strobe function to disorientate your attacker",
person: "Flashlight"
}, {
quote: "Apply liberally to your erogenous zones",
person: "Spice Bomb"
}, {
quote: "Help me, I'm bleaching",
person: "The Great Barrier Reef"
}];
function motivateMe() {
var listLength = Object.keys(motivation).length;
var randVal = Math.floor(Math.random() * listLength);
document.write(motivation[randVal]);
display.innerHTML = motivation;
}
Please help me refine the code and respond below
Thank you