popcorn 1

%%html
<!-- HTML output div -->
<div id="message"></div>

<script>
    function runWhenDOMLoaded() {
        // Example choices
        let appleColor = "green"; // Change this to "green" to test different outcomes
        let eatApple = "no";   // Change this to "no" to test different outcomes

        const messageElement = document.getElementById("message");

        function displayMessage(message) {
            console.log(message); // Log to console
            messageElement.textContent = message; // Display on the webpage
        }

        // Check the color of the apple chosen by the user
        if (appleColor === "green") {
            // If the apple is red, check if the user wants to eat it
            if (eatApple === "no") {
                displayMessage("Lmao, the apple you ate was poisonous. You're dead :D");
            } else {
                displayMessage("You decided not to eat the red apple (You're boring -_-).");
            }
        } else if (appleColor === "green") {
            // If the apple is green, check if the user wants to eat it
            if (eatApple === "no") {
                displayMessage("You ate the green apple.");
            } else {
                displayMessage("You decided not to eat the green apple (You're boring -_-).");
            }
        } else {
            // If the user enters an invalid color, display an error message
            displayMessage("Invalid answer. Please choose 'red' or 'green'.");
        }
    }

    // Ensure the function runs only after the page loads
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', runWhenDOMLoaded);
    } else {
        runWhenDOMLoaded();
    }
</script>
%%js 
<div id="message"></div>

<script>
    function runWhenDOMLoaded() {
        let isHungry = true;

        // Define ingredients as a JSON object
        const ingredients = {
            "bread": false,
            "cheese": false,
            "tomato": true,
        };

        const messageElement = document.getElementById("message");

        function displayMessage(message) {
            console.log(message); // Log to console
            messageElement.textContent = message; // Display on the webpage
        }

        // Check if essential ingredients are available
        if (isHungry) {
            if (ingredients.bread && ingredients.cheese) {
                displayMessage("You can make a cheese sandwich at home.");
            } else if (ingredients.bread) {
                displayMessage("You only have bread, maybe make toast.");
            } else {
                displayMessage("You should order food since you don't have enough ingredients.");
            }
        } else {
            displayMessage("You aren't hungry. Maybe meal-prep for later if you had ingredients.");
        }
    }

    // Ensure the function runs only after the page loads
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', runWhenDOMLoaded);
    } else {
        runWhenDOMLoaded();
    }
</script>

<IPython.core.display.Javascript object>
%%js 
// Generate a random grade between 0 and 12
let grade = Math.round(Math.random() * 12);

// Print the grade
console.log(`You are in ${grade} grade.`);

// Determine the school level
if (grade === 0) {
    console.log("You are in Kindergarten.");
} else if (grade >= 1 && grade <= 5) {
    console.log("You are in Elementary School.");
    
    // Check if the student is in their final year of elementary school
    if (grade === 5) {
        console.log("You will graduate this year from Elementary School.");
    }
} else if (grade >= 6 && grade <= 8) {
    console.log("You are in Middle School.");
    
    // Check if the student is in their final year of middle school
    if (grade === 8) {
        console.log("You will graduate this year from Middle School.");
    }
} else if (grade >= 9 && grade <= 12) {
    console.log("You are in High School.");
    
    // Check if the student is in their final year of high school
    if (grade === 12) {
        console.log("You will graduate this year from High School.");
    }
}
<IPython.core.display.Javascript object>