[JS] Les nombres pairs

  1. Ecrire un script permettant d’afficher les nombres pair <20 ; On affichera (2,4, 6, 8, 10, 12, 14, 16,18) chacun dans une ligne.
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pair</title>
</head>

<body>
    <script language="javascript">
        for (i = 2; i < 19; i = i + 2) {
            document.write(i + "<br>");
        }
    </script>
</body>

</html>

2.Reprendre le script Pair avec la boucle Do..While.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script language="javascript">
        i = 0;
        do {
            i = i + 2;
            document.write(i + "<br>");
        }
        while (i < 18);
    </script>
</body>

</html>

Leave a Reply

Your email address will not be published. Required fields are marked *