123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html lang=fr>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta charset ="UTF-8">
        <!--Google Fonts-->
        <link href="https://fonts.googleapis.com/css?family=Hind+Madurai|Cabin+Condensed|Anton&display=swap" rel="stylesheet">
        <!--Bootstrap-->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" 
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <title>addition</title>
        <link rel="stylesheet" href="css/style.css">
    </head>

    <body class="container-fluid body">
        <section class="container">
            <div class="row" id="number">
                <form method="POST" action="test.php">
                    <p>
                        <label for="nb">entrez le dernier numéro sorti</label> :<br/>
                        <input type="text" id="nb">
                        <button type="button" id="valider">VALIDER</button>
                        <p id="message"></p> 
                    </p>
                </form>
            </div>
            <div class="row" id="numbers">
                <div class="col-md-2" id="total"></div>
            </div>
            <div class="row" id="resultat"></div>
        </section>

        <!-- JQuery -->
        <script
			  src="https://code.jquery.com/jquery-3.4.1.min.js"
			  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
              crossorigin="anonymous">
        </script>
        <!-- Dossier JS -->
        <script src="js/addition.js"></script>
    </body>
</html>
            
          
!
            
              /*-- Body et HTML --*/
body, html{
    margin: 0;
    padding: 0;
}

body{
    background: #085df05c;
    font-family: 'Cabin Condensed', sans-serif;
    font-size: 1.8em;
}

/*-- numéros --*/
#number{
    margin: auto;
    margin-top: 200px;
}

#valider{
    background-color: #358c0e;
    color: white;
    border-radius: 10px;
}

#numbers{
    margin: auto;
}

.chiffres{
    border: 1px solid black;
    padding-left: 30px;
}

#green{
    background-color: green;
}

#yellow{
    background-color: yellow;
}

#blue{
    background-color: lightseagreen;
}

#red{
    background-color: red;
}

#total{
    background-color: #f39c1a;
    padding-left: 65px;
}

#resultat{
    margin-top: 20px;
    margin-left: 10px;
}
            
          
!
            
              $(document).ready(function() {
    // Le tableau de chiffres
    var numbersElt = []; 

    // Selection des éléments du DOM
    var numbers = document.getElementById("numbers");        
    var btn = document.getElementById("valider");
    var number = document.getElementById("nb");
    var resultat = document.getElementById("resultat");
    var message = document.getElementById("message");

    // Fonction pour calculer la somme des chiffres du tableau
    function sum(input){      
        if (toString.call(input) !== "[object Array]")
        return false;

        var total =  0;
        for(var i=0;i<input.length;i++){                  
            if(isNaN(input[i])){
                continue;
            }
            total += Number(input[i]);
        }
        return total;
    }

    // Fonction pour créer les élements du tableau
    function creaElement(i){
        let total = document.getElementById("total");
        let nbElt = document.createElement("div");
        nbElt.className = "col-md-1";
        nbElt.classList.add("chiffres");
        nbElt.textContent = numbersElt[i];

        // Determine la couleur de la div en fonction du chiffre entré
        if (numbersElt[i] >= 0 && numbersElt[i] <= 9){
            nbElt.id = "green";
        } else if (numbersElt[i] >= 10 && numbersElt[i] <= 19){
            nbElt.id = "yellow";
        } else if (numbersElt[i] >= 20 && numbersElt[i] <= 29){
            nbElt.id = "blue";
        } else if (numbersElt[i] >= 30 && numbersElt[i] <= 36){
            nbElt.id = "red";
        }

        numbers.insertBefore(nbElt, total);
    }

    // Fonction pour ajouter les éléments au tableau + affichage des éléments sur le DOM
    function pushData(e){
        e.preventDefault 
        var chiffre = number.value;
        if (chiffre > 36){
            message.innerHTML = "Vous ne pouvez pas rentrer un chiffre plus grand que 36"
        } else {
            numbersElt.push(chiffre);
        }
        console.log('pushdata ',numbersElt.length,number,numbersElt);
        if (numbersElt.length > 10){
            numbersElt.shift();
            console.log('pushdata after shift',numbersElt);
        };
                
        numbers.innerHTML = '<div class="col-md-2" id="total"></div>';
        number.value = "";
        
        // Création de la div en fonction du chiffre entré 
        for (var i= 0; i < numbersElt.length; i++) {
            creaElement(i);
        };

        // Calcul de la somme des chiffres du tableau
        var somme = sum(numbersElt);
        total.append(somme);
        
        // Récupère le dernier chiffre de la somme
        var result = somme.toString()[2]

        // Selection des éléments crées dynamiquement
        var $green = $("#green");
        var $yellow = $("#yellow");
        var $blue = $("#blue");
        var $red = $("#red");

        // Renvoi une suite de chiffres en fonction du résultat de la somme du tableau
        var phrase = "";
        if (numbersElt.length < 10){
            phrase = "Pas de numéros à jouer";
        } else if(!$green.length || !$yellow.length || !$blue.length || !$red.length){
            if(result === "3" || result === "1"){
                phrase = "Jouez les numéros suivants : 1-3-11-13-21-23-21-33";
            } else if (result === "6" || result === "8"){
                phrase = "Jouez les numéros suivants : 6-8-16-18-26-28-36";
            } else if (result === "0"){
                phrase = "Jouez les numéros suivants : 0-2-10-12-20-22-30-32";
            } else if (result === "5"){
                phrase = "Jouez les numéros suivants : 5-7-15-17-25-27-35";
            } else if (result === "2" || result === "4"){
                phrase = "Jouez les numéros suivants : 2-4-12-14-22-24-32-34";
            } else if (result === "7" || result === "9"){
                phrase = "Jouez les numéros suivants : 7-9-17-19-27-29";
            }
        } else if ($green.length || $yellow.length || $blue.length || $red.length){
            phrase = "Pas de numéros à jouer";
        }
        // Ajout du résultat dans le DOM
        resultat.innerHTML = phrase;
    }

    // Evnmt click sur bouton valider
    btn.addEventListener("click", pushData);
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console