-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdé.html
34 lines (30 loc) · 1.3 KB
/
dé.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dé</title>
</head>
<body>
<h1>Dé</h1>
<p id="resultat_texte"></p>
<img id="dé_image" src="" alt="Résultat" width="200">
<script>
// 1 : Aléatoire
const déResultat = Math.floor(Math.random() * 6) + 1;
// 2 : Les valeurs sont assignées par des images
const déImages = {
1: 'https://cdn.pixabay.com/photo/2014/04/03/11/56/dice-312625_1280.png',
2: 'https://cdn.pixabay.com/photo/2014/04/03/11/56/dice-312627_1280.png',
3: 'https://cdn.pixabay.com/photo/2014/04/03/11/56/dice-312624_1280.png',
4: 'https://cdn.pixabay.com/photo/2014/04/03/11/56/dice-312623_1280.png',
5: 'https://cdn.pixabay.com/photo/2014/04/03/11/56/dice-312622_1280.png',
6: 'https://cdn.pixabay.com/photo/2014/04/03/11/56/dice-312621_1280.png'
};
// 4 : Met à jour le texte du résultat
document.getElementById('resultat_texte').innerText = `Vous avez obtenu la face du dé : ${déResultat} !`;
// 5 : Met à jour l'image affichée
document.getElementById('dé_image').src = déImages[déResultat];
</script>
</body>
</html>