Exercices
Pour réaliser ces exercices, vous utiliserez l'interface HTML fournies (index.html) reliée au fichier JavaScript (script.js). N'ajoutez pas de balises HTML : appuyez-vous sur les identifiants (id) et événements déjà présents dans le document. Pour observer les résultats dans la console, utilisez la touche F12 ou Ctrl+Maj+I.
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Exercices JavaScript - Partie 2</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="script.js" defer></script>
</head>
<body class="bg-slate-100 font-sans p-6 text-slate-800">
<header class="max-w-4xl mb-4 mx-auto space-y-6">
<h1 class="text-3xl font-bold text-slate-900 mb-2">
Exercices JavaScript — Partie 2
</h1>
<p class="text-slate-600 text-sm">
Structures de contrôle, conditions et boucles avec manipulation du DOM.
</p>
</header>
<main class="max-w-4xl mx-auto space-y-6">
<!-- Ex 1 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 1 : Test de majorité (if / else)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="ageUtilisateur" class="sr-only"
>Âge de l'utilisateur</label
><input
type="number"
id="ageUtilisateur"
placeholder="Âge"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="verifierMajorite()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Vérifier
</button>
</form>
<output
id="resultatMajorite"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem]"
></output>
</section>
<!-- Ex 2 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 2 : Évaluation d'une note minimale (Ternaire)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="noteExamen" class="sr-only"
>Note de l'examen sur 20</label
><input
type="number"
id="noteExamen"
placeholder="Note /20"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="evaluerNote()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Évaluer
</button>
</form>
<output
id="resultatAdmission"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem]"
></output>
</section>
<!-- Ex 3 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 3 : Comparaison Strictement Égal (== vs ===)
</h2>
<button
type="button"
onclick="comparerEgalite()"
class="bg-slate-800 hover:bg-slate-900 text-white font-medium px-4 py-2 rounded-lg transition"
>Lancer la comparaison (Console)
</button>
<p class="text-xs text-slate-500 mt-2">
Ouvrez la console du navigateur (<kbd
class="bg-slate-100 border px-1 rounded"
>F12</kbd
>) pour voir les logs.</p>
</section>
<!-- Ex 4 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 4 : Attribution de mention (if / else if / else)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="moyenneEtudiant" class="sr-only"
>Moyenne de l'étudiant</label
><input
type="number"
id="moyenneEtudiant"
placeholder="Moyenne"
step="0.5"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="obtenirMention()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Obtenir la mention
</button>
</form>
<output
id="affichageMention"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem]"
></output>
</section>
<!-- Ex 5 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 5 : Vérification d'accès VIP (&& et ||)</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-4 items-center"
><label for="ageVip" class="sr-only">Âge du visiteur</label>
<input
type="number"
id="ageVip"
placeholder="Âge"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><label
class="inline-flex items-center gap-2 cursor-pointer select-none text-sm font-medium text-slate-700"
><input
type="checkbox"
id="possedeInvitation"
class="w-4 h-4 text-blue-600 rounded border-slate-300 focus:ring-blue-500"
/>Invitation ?
</label>
<button
type="button"
onclick="verifierVip()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Vérifier l'accès
</button>
</form>
<output
id="resultatVip"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem]"
></output>
</section>
<!-- Ex 6 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 6 : Jours de la semaine (switch)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="numeroJour" class="sr-only">Numéro du jour</label>
<input
type="number"
id="numeroJour"
placeholder="Jour (1-7)"
class="border border-slate-300 rounded-lg px-3 py-2 w-36 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="convertirJour()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Convertir
</button>
</form>
<output
id="nomJour"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem]"
></output>
</section>
<!-- Ex 7 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 7 : Table de multiplication (for)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="nombreTable" class="sr-only">Nombre pour la table</label>
<input
type="number"
id="nombreTable"
placeholder="Nombre"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="genererTable()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Générer
</button>
</form>
<pre
id="affichageTable"
class="mt-3 bg-slate-50 p-3 rounded-lg border border-slate-200 font-mono text-sm text-slate-800 min-h-[2.5rem] whitespace-pre-wrap"
></pre>
</section>
<!-- Ex 8 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 8 : Décompte interactif (while)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="valeurDepart" class="sr-only"
>Valeur de départ du décompte</label
><input
type="number"
id="valeurDepart"
placeholder="Départ (ex: 5)"
class="border border-slate-300 rounded-lg px-3 py-2 w-36 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="lancerDecompte()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Lancer
</button>
</form>
<output
id="resultatDecompte"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem]"
></output>
</section>
<!-- Ex 9 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 9 : Calcul de somme d'entiers (Accumulateur)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="nombreN" class="sr-only">Nombre N</label>
<input
type="number"
id="nombreN"
placeholder="N (ex: 10)"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="calculerSomme()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Calculer la somme
</button>
</form>
<output
id="resultatSomme"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem]"
></output>
</section>
<!-- Ex 10 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 10 : Filtre de nombres pairs
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="limitePair" class="sr-only">Limite pour les pairs</label>
<input
type="number"
id="limitePair"
placeholder="Limite (ex: 20)"
class="border border-slate-300 rounded-lg px-3 py-2 w-36 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="filtrerPairs()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Filtrer
</button>
</form>
<output
id="listePairs"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem] break-words"
></output>
</section>
<!-- Ex 11 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 11 : Validation de mot de passe
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="motDePasse" class="sr-only">Mot de passe</label>
<input
type="password"
id="motDePasse"
placeholder="Mot de passe"
class="border border-slate-300 rounded-lg px-3 py-2 w-48 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="validerMotDePasse()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Valider
</button>
</form>
<output
id="feedbackMotDePasse"
class="block mt-3 font-semibold min-h-[1.5rem]"
></output>
</section>
<!-- Ex 12 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 12 : Calculateur de remises progressives
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="montantTotal" class="sr-only"
>Montant total en euros</label
><input
type="number"
id="montantTotal"
placeholder="Montant €"
class="border border-slate-300 rounded-lg px-3 py-2 w-36 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="calculerRemise()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Calculer le net
</button>
</form>
<output
id="resultatRemise"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem] whitespace-pre-line"
></output>
</section>
<!-- Ex 13 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 13 : Générateur de Motifs (Boucles imbriquées)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="nombreLignes" class="sr-only">Nombre de lignes</label>
<input
type="number"
id="nombreLignes"
placeholder="Lignes"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="genererMotif()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Générer
</button>
</form>
<pre
id="affichageMotif"
class="mt-3 bg-slate-900 text-amber-400 p-3 rounded-lg font-mono text-sm leading-none min-h-[2.5rem] whitespace-pre"
></pre>
</section>
<!-- Ex 14 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 14 : Jeu du Nombre Mystère
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="propositionNombre" class="sr-only"
>Proposition de nombre</label
><input
type="number"
id="propositionNombre"
placeholder="Nombre (1-100)"
class="border border-slate-300 rounded-lg px-3 py-2 w-40 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="jouerNombreMystere()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Tester
</button>
</form>
<output
id="statutJeu"
class="block mt-3 font-semibold text-slate-700 min-h-[1.5rem]"
></output>
</section>
<!-- Ex 15 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-4">
Exercice 15 : Synthèse — Simulation DAB
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="soldeCompte" class="sr-only">Solde initial</label>
<input
type="number"
id="soldeCompte"
placeholder="Solde initial €"
value="500"
class="border border-slate-300 rounded-lg px-3 py-2 w-36 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><label for="typeOperation" class="sr-only">Type d'opération</label>
<select
id="typeOperation"
class="border border-slate-300 rounded-lg px-3 py-2 bg-white focus:outline-none focus:ring-2 focus:ring-blue-500"
><option value="retrait">Retrait</option>
<option value="depot">Dépôt</option>
</select>
<label for="montantOperation" class="sr-only"
>Montant de l'opération</label
><input
type="number"
id="montantOperation"
placeholder="Montant €"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="traiterDab()"
class="bg-emerald-600 hover:bg-emerald-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Valider l'opération
</button>
</form>
<output
id="resultatDab"
class="block mt-4 p-4 rounded-lg bg-slate-50 border border-slate-200 font-medium text-slate-700 min-h-[2rem] whitespace-pre-line"
></output>
</section>
<!-- Ex 16 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 16 : Affichage d'une alerte stylisée (if / else &innerHTML)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="ageAlerte" class="sr-only">Âge de contrôle</label>
<input
type="number"
id="ageAlerte"
placeholder="Âge"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="afficherAlerte()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Tester l'accès
</button>
</form>
<output id="conteneurAlerte" class="block mt-3 min-h-[2.5rem]"></output>
</section>
<!-- Ex 17 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 17 : Génération d'une liste à puces (for & innerHTML)</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="nombreListe" class="sr-only">Nombre d'éléments</label>
<input
type="number"
id="nombreListe"
placeholder="Nombre"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="genererListeHtml()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Générer la liste
</button>
</form>
<output id="conteneurListe" class="block mt-3 min-h-[2.5rem]"></output>
</section>
<!-- Ex 18 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 18 : Galerie de mentions stylisées (switch & innerHTML)</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="noteBadge" class="sr-only">Note pour le badge</label>
<input
type="number"
id="noteBadge"
placeholder="Note /20"
class="border border-slate-300 rounded-lg px-3 py-2 w-32 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="afficherBadgeMention()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Afficher le badge
</button>
</form>
<output id="conteneurBadge" class="block mt-3 min-h-[2.5rem]"></output>
</section>
<!-- Ex 19 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 19 : Compteur visuel de cartes (while & innerHTML)</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="nombreCartes" class="sr-only">Nombre de cartes</label>
<input
type="number"
id="nombreCartes"
placeholder="Nombre de cartes"
class="border border-slate-300 rounded-lg px-3 py-2 w-44 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="genererCartes()"
class="bg-blue-600 hover:bg-blue-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Générer les cartes
</button>
</form>
<output
id="conteneurCartes"
class="flex flex-wrap gap-3 mt-4 min-h-[2.5rem]"
></output>
</section>
<!-- Ex 20 --><section
class="bg-white p-6 rounded-xl shadow-sm border border-slate-200"
><h2 class="text-lg font-semibold text-slate-800 mb-3">
Exercice 20 : Synthèse — Ticket de caisse dynamique (innerHTML)
</h2>
<form
onsubmit="return false;"
class="flex flex-wrap gap-3 items-center"
><label for="montantTicket" class="sr-only">Montant d'achat</label>
<input
type="number"
id="montantTicket"
placeholder="Montant Achat €"
class="border border-slate-300 rounded-lg px-3 py-2 w-40 focus:outline-none focus:ring-2 focus:ring-blue-500"
/><button
type="button"
onclick="genererTicketCaisse()"
class="bg-emerald-600 hover:bg-emerald-700 text-white font-medium px-4 py-2 rounded-lg transition"
>Générer le ticket
</button>
</form>
<output id="conteneurTicket" class="block mt-4 min-h-[2.5rem]"></output>
</section>
</main>
</body>
</html>
Syntaxe : Exercice 1 : Test de majorité (if / else)
Récupérez la valeur du champ d'âge via
document.querySelectoret la propriété.value.Si l'âge est supérieur ou égal à 18 :
Affichez "Majeur", sinon "Mineur".
Modifiez le style du texte en changeant sa classe Tailwind grâce à l'instruction :
element.className = 'valeur'(ex: 'text-emerald-600' pour le vert, 'text-rose-600' pour le rouge).
Syntaxe : Exercice 2 : Évaluation d'une note minimale (Ternaire)
Récupérez la note via
document.querySelector.Utilisez une condition ternaire pour stocker "Admis" si la note est >= 10, sinon "Ajourné".
Affichez le résultat dans le paragraphe de rendu via
.textContent.
Syntaxe : Exercice 3 : Comparaison Strictement Égal (== vs ===)
Créez une fonction déclenchée au clic qui compare le nombre 100 et la chaîne "100" avec == puis avec ===, et affichez les résultats dans la console avec console.log().
Syntaxe : Exercice 4 : Attribution de mention (if / else if / else)
Récupérez la moyenne.
Affichez "Insuffisant" (< 10), "Passable" (< 12), "Assez Bien" (< 14) ou "Bien" (>= 14) en modifiant le
.textContentde l'élément ciblé.
Syntaxe : Exercice 5 : Vérification d'accès VIP (&& et ||)
Récupérez l'âge via
.value.Vérifier si la case à cocher est cochée, utilisez l'instruction :
element.checked(qui renvoie true ou false).Accordez l'accès si l'utilisateur est majeur ET a une invitation, OU s'il a plus de 65 ans.
Syntaxe : Exercice 6 : Jours de la semaine (switch)
Récupérez un numéro de 1 à 7 .
Affichez le jour correspondant grâce à une structure
switch.Affichez un message d'erreur si le nombre est invalide.
Syntaxe : Exercice 7 : Table de multiplication (for)
À l'aide d'une boucle for :
Générez la table de multiplication (de 1 à 10) du nombre saisi.
Affichez le résultat ligne par ligne dans la balise <pre>.
Syntaxe : Exercice 8 : Décompte interactif (while)
À partir d'un nombre de départ, utilisez une boucle while pour construire une chaîne de décompte (ex: "5... 4... 3... 2... 1... 0... Décollage !").
Syntaxe : Exercice 9 : Calcul de somme d'entiers (Accumulateur)
Calculez la somme des entiers de 1 jusqu'au nombre N saisi en utilisant une boucle et une variable accumulateur.
Syntaxe : Exercice 10 : Filtre de nombres pairs
Parcourez tous les nombres de 1 jusqu'à la limite saisie. Affichez uniquement les nombres pairs séparés par une virgule.
Syntaxe : Exercice 11 : Validation de mot de passe
Vérifiez la longueur de la chaîne saisie via la propriété
.length.Affichez un message vert ("Valide") si elle contient au moins 8 caractères, ou rouge sinon.
Syntaxe : Exercice 12 : Calculateur de remises progressives
Calculez le prix net :
0% de remise sous 50€,
10% entre 50€ et 100€,
20% au-delà de 100€.
Affichez le montant de la remise et le prix final.
Syntaxe : Exercice 13 : Générateur de Motifs (Boucles imbriquées)
Construisez une pyramide d'étoiles (*) en fonction du nombre de lignes saisi, en utilisant deux boucles for imbriquées.
Syntaxe : Exercice 14 : Jeu du Nombre Mystère
Comparez la saisie avec le nombre secret (ex: 42) :
Décrémentez le nombre d'essais (max 5) à chaque tentative.
Affichez si le nombre est plus grand ou plus petit.
Syntaxe : Exercice 15 : Synthèse - Simulation DAB
Gérez les dépôts et retraits sur un solde bancaire.
Empêchez les retraits supérieurs au solde disponible.
Mettez à jour la valeur du champ solde.
Syntaxe : Exercice 16 : Affichage d'une alerte stylisée (if / else & innerHTML)
Récupérez la valeur du champ d'âge via
.value.Si l'utilisateur est majeur, injectez le composant HTML
<div class="alert success">Accès autorisé</div>avecinnerHTML.Sinon, injectez le composant
<div class="alert danger">Accès refusé</div>dans le même conteneur.
Syntaxe : Exercice 17 : Génération d'une liste à puces (for & innerHTML)
Récupérez le nombre choisi par l'utilisateur.
À l'aide d'une boucle
for, construisez une chaîne HTML contenant des balises<ul>et<li>.Affichez la table de multiplication sous forme de liste structurée dans la page via
innerHTML.
Syntaxe : Exercice 18 : Galerie de mentions stylisées (switch & innerHTML)
Récupérez la note saisie par l'étudiant.
Utilisez une structure
switchpour déterminer la tranche d'évaluation.Générez et injectez un badge HTML personnalisé (ex:
<span class="badge badge-warning">Passable</span>) avecinnerHTML.
Syntaxe : Exercice 19 : Compteur visuel de cartes (while & innerHTML)
Lisez la quantité de cartes N demandée dans le formulaire.
Générez N blocs HTML de cartes (
<div class="card">Jeton n°X</div>) grâce à une bouclewhile.Injectez l'ensemble des éléments dans le conteneur visuel en une seule fois via
innerHTML.
Syntaxe : Exercice 20 : Synthèse - Ticket de caisse dynamique (innerHTML)
Calculez le prix net en fonction de la remise appliquée.
Construisez un tableau HTML récapitulatif complet à l'aide des balises
<table>,<tr>et<td>.Insérez ce ticket de caisse dans l'élément cible en utilisant
innerHTML.