🤣 Giggle Engine

Press the button for a laugh!

💻 The Code Behind the Laughs

This is the real JavaScript code running this page!

// 1. We create a list (Array) of jokes
const jokes = [
    "Why did the cookie go to the hospital? Because he felt crummy!",
    "What do you call a sleeping dinosaur? A dino-snore!",
    "Why was the math book sad? Because it had too many problems."
];

// 2. This function runs when the button is clicked
function tellJoke() {
    // Pick a random number between 0 and the list length
    const randomIndex = Math.floor(Math.random() * jokes.length);
    
    // Get the text from the list
    const selectedJoke = jokes[randomIndex];

    // Put the text into the HTML element
    document.getElementById('joke-display').innerText = selectedJoke;
    
    // Change background color randomly!
    const randomColor = '#' + Math.floor(Math.random()*16777215).toString(16);
    document.getElementById('giggle-container').style.backgroundColor = randomColor;
}