Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                    <div class="container">
        <h1>Trouve le nombre !</h1>
        <p>Trouve le bon nombre entre 0 et 100. Tu as 5 essais !</p>
        <div class="vies">
            <ion-icon name="heart-outline"></ion-icon>
            <ion-icon name="heart"></ion-icon>
        </div>

        <form id="inputBox">
            <label for="number">Entrez un nombre :</label>
            <input type="number" id="number" min="0" max="100" required>
            <button type="submit" id="essayerBtn">Essayer</button>
            <p id="message"></p>
            <button id="rejouer">Rejouer ?</button>
        </form>
        <p id="details">* Brûlant = &plusmn; 2 ; Chaud = &plusmn; 5 ; Tiède = &plusmn; 10 ; Froid = + de 10. </p>
    </div>

    <script src="https://unpkg.com/[email protected]/dist/ionicons.js"></script>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Luckiest+Guy&display=swap");

:root {
    --title: #f8c27a;
    --textShadow: 0 2px 2px rgba(0, 0, 0, 0.7);
    --boxShadow: 0 0px 10px rgba(0, 0, 0, 0.2);
}

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

body {
    font-size: 14px;
    width: 100vw;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: sans-serif;
    background-image: linear-gradient(120deg, #d4fc79 0%, #96e6a1 100%);
}

.container {
    background-color: rgba(255, 255, 255, 0.2);
    padding: 20px;
    border-radius: 5px;
    text-align: center;
    box-shadow: var(--boxShadow);
}

h1 {
    font-family: "Luckiest Guy", cursive;
    margin-bottom: 15px;
    color: #ffc31d;
    text-shadow: var(--textShadow);
    display: inline-block;
}

.vies {
    margin: 10px;
}

ion-icon {
    font-size: 50px;
    fill: red;
}

#inputBox {
    background-color: #96e6a1;
    padding: 15px;
    border-radius: 5px;
}

#inputBox > label {
    display: block;
    margin-bottom: 8px;
}

input,
button {
    outline: none;
    border: none;
    padding: 3px 20px;
    border-radius: 5px;
}

button {
    background-color: teal;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s;
}

button:hover {
    transform: translateY(-2px);
    background-color: rgb(0, 184, 184);
}

p#message {
    margin: 20px auto 0 auto;
}

#rejouer {
    display: none;
    margin: 5px auto 0 auto;
}

#details {
    font-weight: bold;
    font-size: 6px;
    margin-top: 5px;
}

              
            
!

JS

              
                // Elements du DOM
const divVies = document.querySelector(".vies");
const message = document.getElementById("message");
const formulaire = document.getElementById("inputBox");
const input = document.getElementById("number");
const essayerBtn = document.getElementById("essayerBtn");
const rejouerBtn = document.getElementById("rejouer");
const body = document.getElementsByTagName("body")[0];

// Modèle de coeurs
const coeurVide = '<ion-icon name="heart-outline"></ion-icon>';
const coeurPlein = '<ion-icon name="heart"></ion-icon>';

// Fond
const bgFroid = "linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%)";
const bgTiede = "linear-gradient(120deg, #f6d365 0%, #fda085 100%)";
const bgChaud = "linear-gradient(-60deg, #ff5858 0%, #f09819 100%)";
const bgBrulant = "linear-gradient(to top, #ff0844 0%, #ffb199 100%)";

const bgWin =
    "linear-gradient(-225deg, #231557 0%, #44107A 29%, #FF1361 67%, #FFF800 100%)";
const bgLoose = "linear-gradient(60deg, #29323c 0%, #485563 100%)";

// PLAY :
const play = () => {
    // nombre aléatoire
    const randomNumber = Math.floor(Math.random() * 101); // 3
    const totalVies = 6;
    let vies = totalVies;
    console.log(randomNumber);

    // Actualisation à chaque essai - TOUTE LA LOGIQUE
    formulaire.addEventListener("submit", (e) => {
        e.preventDefault();
        const valeurInput = parseInt(input.value);

        if (valeurInput < 0 || valeurInput > 100) return;

        if (valeurInput === randomNumber) {
            body.style.backgroundImage = bgWin;
            message.textContent = `BRAVO !!! Le nombre était bien ${randomNumber}`;
            rejouerBtn.style.display = "block";
            essayerBtn.setAttribute("disabled", "");
        }

        if (valeurInput !== randomNumber) {
            if (
                randomNumber < valeurInput + 3 &&
                randomNumber > valeurInput - 3
            ) {
                body.style.backgroundImage = bgBrulant;
                message.textContent = "C'est Brûlant !!! 🔥🔥🔥 ";
            } else if (
                randomNumber < valeurInput + 6 &&
                randomNumber > valeurInput - 6
            ) {
                body.style.backgroundImage = bgChaud;
                message.textContent = "C'est Chaud ! 🔥 ";
            } else if (
                randomNumber < valeurInput + 11 &&
                randomNumber > valeurInput - 11
            ) {
                body.style.backgroundImage = bgTiede;
                message.textContent = "C'est Tiède 😐 ";
            } else {
                body.style.backgroundImage = bgFroid;
                message.textContent = "C'est Froid ❄️ ";
            }
            vies--;
            verifyLoose();
        }

        actualiseCoeurs(vies);
    });

    const verifyLoose = () => {
        if (vies === 0) {
            body.style.backgroundImage = bgLoose;
            body.style.color = "#990000";
            essayerBtn.setAttribute("disabled", "");
            message.textContent = `Vous avez perdu. La réponse était ${randomNumber}`;
            rejouerBtn.style.display = "block";
        }
    };

    const actualiseCoeurs = (vies) => {
        // total : 6; vies : 4
        divVies.innerHTML = "";
        let tableauDeVies = [];
        for (let i = 0; i < vies; i++) {
            tableauDeVies.push(coeurPlein);
        }
        for (let i = 0; i < totalVies - vies; i++) {
            tableauDeVies.push(coeurVide);
        }
        tableauDeVies.forEach((coeur) => {
            divVies.innerHTML += coeur;
        });
    };
    actualiseCoeurs(vies);

    rejouerBtn.addEventListener("click", () => {
        message.style.display = "none";
        document.location.reload(true);
    });
};

play();

              
            
!
999px

Console