Jeu de dés javascript
Résolu
genidou
Messages postés
10
Date d'inscription
Statut
Membre
Dernière intervention
-
genidou -
genidou -
Bonjour,
je dois simuler 50 lancés de 5 dés et compter le nombre d'occurence de chacune des valeurs.. voila ce que j'ai fais ... quelqu'un peu m'aider aucun résultat s'affiche... merci d'avance
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<LINK HREF="Base.CSS" REL="stylesheet" TYPE="text/css">
<title>Tp2 IFT1144, numéro 3
</title>
</head>
<body>
<table border=0 cellspacing=0 cellpadding=10 cols=2 width="92%">
<tr>
<td width="1%">
<img border="0" src="UMlogo.gif" width="110" height="50" alt="UdeM"></a></td>
</td>
<td width="100%"><h1> ift1144, tp2 numéro 3 </h1>
</td>
</tr>
<tr>
</tr>
</table>
<table border=0 cellspacing=0 cellpadding=10 cols=4 width="100%">
<tr>
</tr>
<tr>
<td width="1%">
</td>
<td width="99%"><h2> Table de fréquence de tirage de dés </h2>
</td>
</tr>
</table>
<script>
do {
function lancerDe(max){
return Math.floor(Math.random() * 10);
}
while face1+face2+face3+face4+face5+face6==500
}
var D1, D2, D3, D4, D5
D1 = lancerDe(6);
D2 = lancerDe(6);
D3 = lancerDe(6);
D4 = lancerDe(6);
D5 = lancerDe(6);
var freq = new Array(6);
var face1=0,face2=0,face3=0,face4=0,face5=0,face6=0;
if lancerDe==1 {
face1++;
}
if lancerDe==2 {
face2++;
}
else if lancerDe==3 {
face3++;
}
else if lancerDe==4 {
face4++;
}
else if lancerDe==5 {
face5++;
}
else lancerDe==6 {
face6++;
}
</script>
<body>
<table border="1" width="50%" align="center">
<tr>
<td align="center"> Dé </td>
<td align="center"> Fréquence</td>
</tr>
<tr>
<td align="right"> 1 </td>
<td align="right"> <script>document.write(face1)</script> </ </td>
</tr>
<tr>
<td align="right"> 2 </td>
<td align="right"> <script>document.write(face2)</script> </td>
</tr>
<tr>
<td align="right"> 3 </td>
<td align="right"> <script>document.write(face3)</script> </td>
</tr>
<tr>
<td align="right"> 4 </td>
<td align="right"> <script>document.write(face4)</script> </td>
</tr>
<tr>
<td align="right"> 5 </td>
<td align="right"> <script>document.write(face5)</script> </td>
</tr>
<tr>
<td align="right"> 6 </td>
<td align="right"> <script>document.write(face6)</script> </td>
</tr>
</table>
<br>
<br><h3>Travail effectué par: Geneviève Hénault</h3>
</body>
</html>
je dois simuler 50 lancés de 5 dés et compter le nombre d'occurence de chacune des valeurs.. voila ce que j'ai fais ... quelqu'un peu m'aider aucun résultat s'affiche... merci d'avance
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<LINK HREF="Base.CSS" REL="stylesheet" TYPE="text/css">
<title>Tp2 IFT1144, numéro 3
</title>
</head>
<body>
<table border=0 cellspacing=0 cellpadding=10 cols=2 width="92%">
<tr>
<td width="1%">
<img border="0" src="UMlogo.gif" width="110" height="50" alt="UdeM"></a></td>
</td>
<td width="100%"><h1> ift1144, tp2 numéro 3 </h1>
</td>
</tr>
<tr>
</tr>
</table>
<table border=0 cellspacing=0 cellpadding=10 cols=4 width="100%">
<tr>
</tr>
<tr>
<td width="1%">
</td>
<td width="99%"><h2> Table de fréquence de tirage de dés </h2>
</td>
</tr>
</table>
<script>
do {
function lancerDe(max){
return Math.floor(Math.random() * 10);
}
while face1+face2+face3+face4+face5+face6==500
}
var D1, D2, D3, D4, D5
D1 = lancerDe(6);
D2 = lancerDe(6);
D3 = lancerDe(6);
D4 = lancerDe(6);
D5 = lancerDe(6);
var freq = new Array(6);
var face1=0,face2=0,face3=0,face4=0,face5=0,face6=0;
if lancerDe==1 {
face1++;
}
if lancerDe==2 {
face2++;
}
else if lancerDe==3 {
face3++;
}
else if lancerDe==4 {
face4++;
}
else if lancerDe==5 {
face5++;
}
else lancerDe==6 {
face6++;
}
</script>
<body>
<table border="1" width="50%" align="center">
<tr>
<td align="center"> Dé </td>
<td align="center"> Fréquence</td>
</tr>
<tr>
<td align="right"> 1 </td>
<td align="right"> <script>document.write(face1)</script> </ </td>
</tr>
<tr>
<td align="right"> 2 </td>
<td align="right"> <script>document.write(face2)</script> </td>
</tr>
<tr>
<td align="right"> 3 </td>
<td align="right"> <script>document.write(face3)</script> </td>
</tr>
<tr>
<td align="right"> 4 </td>
<td align="right"> <script>document.write(face4)</script> </td>
</tr>
<tr>
<td align="right"> 5 </td>
<td align="right"> <script>document.write(face5)</script> </td>
</tr>
<tr>
<td align="right"> 6 </td>
<td align="right"> <script>document.write(face6)</script> </td>
</tr>
</table>
<br>
<br><h3>Travail effectué par: Geneviève Hénault</h3>
</body>
</html>
A voir également:
- Jeu de dé javascript
- 94 jeu - Télécharger - Puzzle & Réflexion
- Jeux de moto: jeu de course 3d - Télécharger - Course
- 94 degrés jeu - Télécharger - Divers Jeux
- Jeu zuma - Télécharger - Jeux vidéo
- Jeu de logo - Télécharger - Jeux vidéo
1 réponse
Bonjour Genidou,
Je vois plusieurs problèmes dans ton script, le voici corrigé (réadapte le pour ajouter ta mise en forme) :
Les principales erreurs :
- tu as 2 tags body dans ton html, ça ne peut pas aller
- tu ne mets pas de ";" après var D1, D2, D3, D4, D5, D6
- tu n'appelles jamais ta fonction javascript (moi je le fais dès que ma page est chargée : <body onLoad="...">)
Cordialement,
Je vois plusieurs problèmes dans ton script, le voici corrigé (réadapte le pour ajouter ta mise en forme) :
<html> <head> <title>Test CCM - Jeu de dés</title> <script style="text/javascript"> /*Script ne fonctionnant que pour des dés à 6faces*/ freq = new Array(0, 0, 0, 0, 0, 0); function lancerDe(){ return Math.floor(Math.random() * 6); } function compute(nbDes, nbLancers) { for (var i = 0; i < nbLancers; i++) { for (var j = 0; j < nbDes; j++) { valeur = lancerDe(); freq[valeur] ++; } } //remplir le tableau affichant les résultats : fillTable(); } function fillTable() { for (var i = 0; i < 6; i++) { var column = document.getElementById(i); column.innerHTML = freq[i]; } } </script> </head> <body onLoad="compute(5, 50);"> <table border="1" width="50%" align="center"> <tr> <th align="center"> Dé </td> <th align="center"> Fréquence</td> </tr> <tr> <td align="right"> 1 </td> <td align="right" id="0"></td> </tr> <tr> <td align="right"> 2 </td> <td align="right" id="1"></td> </tr> <tr> <td align="right"> 3 </td> <td align="right" id="2"></td> </tr> <tr> <td align="right"> 4 </td> <td align="right" id="3"></td> </tr> <tr> <td align="right"> 5 </td> <td align="right" id="4"></td> </tr> <tr> <td align="right"> 6 </td> <td align="right" id="5"></td> </tr> </table> </body> </html>
Les principales erreurs :
- tu as 2 tags body dans ton html, ça ne peut pas aller
- tu ne mets pas de ";" après var D1, D2, D3, D4, D5, D6
- tu n'appelles jamais ta fonction javascript (moi je le fais dès que ma page est chargée : <body onLoad="...">)
Cordialement,
genidou
Merci mille fois...