Tirage de 3 chiffres au hasard
gen
-
CrazyWorld Messages postés 326 Date d'inscription Statut Membre Dernière intervention -
CrazyWorld Messages postés 326 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je dois afficher 3 chiffres au hasard entre 0 et 9 sauf la ca m'affiche undefined... quelqu'un peu m'aider je suis débutante ... voila mon code... merci
<!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 1
</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 1 </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> Tirage de la Quotidienne 3 chiffres </h2>
</td>
</tr>
</table>
<script>
var qu1, qu2, qu3;
function chiffreAleatoire (max){
return Math.floor(math.random() *(max*10+1));
}
qu1= chiffreAleatoire(9);
qu2= chiffreAleatoire(9);
qu3= chiffreAleatoire(9);
</script>
<table border="1" width="50%" align="center">
<tr>
<td align="center"> <script>document.write(qu1)</script></td>
<td align="center"> <script>document.write(qu2)</script></td>
<td align="center"> <script>document.write(qu3)</script></td>
</tr>
</table
<body>
</body>
</html>
Je dois afficher 3 chiffres au hasard entre 0 et 9 sauf la ca m'affiche undefined... quelqu'un peu m'aider je suis débutante ... voila mon code... merci
<!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 1
</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 1 </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> Tirage de la Quotidienne 3 chiffres </h2>
</td>
</tr>
</table>
<script>
var qu1, qu2, qu3;
function chiffreAleatoire (max){
return Math.floor(math.random() *(max*10+1));
}
qu1= chiffreAleatoire(9);
qu2= chiffreAleatoire(9);
qu3= chiffreAleatoire(9);
</script>
<table border="1" width="50%" align="center">
<tr>
<td align="center"> <script>document.write(qu1)</script></td>
<td align="center"> <script>document.write(qu2)</script></td>
<td align="center"> <script>document.write(qu3)</script></td>
</tr>
</table
<body>
</body>
</html>
A voir également:
- Tirage de 3 chiffres au hasard
- Ai suite 3 - Télécharger - Optimisation
- Combien de possibilités pour un code à 3 chiffres - Forum loisirs/vie pratique
- :3 emoji ✓ - Forum Mail
- 3 emoji - Forum Mail
- Picasa 3 - Télécharger - Albums photo
2 réponses
Hello
essaye d' utiliser un truc du genre
essaye d' utiliser un truc du genre
<script>
function chiffreAleatoire (){
var nb1 = Math.floor(Math.random() * 10);
var nb2 = Math.floor(Math.random() * 10);
var nb3 = Math.floor(Math.random() * 10);
alert(nb1);
alert(nb2);
alert(nb3);
}
chiffreAleatoire ();
</script>
Je viens de te modifier ta source en utlisant du php à la place du JavaSvcript
Et ca marche ^^
<? mt_srand((float) microtime()*1000000); $nb1= mt_rand(0, 9); $nb2= mt_rand(0, 9); $nb3= mt_rand(0, 9); ?> <!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 1 </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 1 </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> Tirage de la Quotidienne 3 chiffres </h2> </td> </tr> </table> <table border="1" width="50%" align="center"> <tr> <td align="center"><? echo $nb1;?></td> <td align="center"><? echo $nb2;?></td> <td align="center"><? echo $nb3;?></td> </tr> </table> <br> <br><h3>Travail effectué par: Geneviève Hénault</h3> </body> </html>
Et ca marche ^^
"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 1
</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 1 </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> Tirage de la Quotidienne 3 chiffres </h2>
</td>
</tr>
</table>
<script>
function chiffreAleatoire (max){
var nb1 = Math.floor(Math.random() * 10);
var nb2 = Math.floor(Math.random() * 10);
var nb3 = Math.floor(Math.random() * 10);
}
nb1 = chiffreAleatoire(9);
nb2 = chiffreAleatoire(9);
nb3 = chiffreAleatoire(9);
</script>
<body>
<table border="1" width="50%" align="center">
<tr>
<td align="center"> <script>document.write(nb1)</script></td>
<td align="center"> <script>document.write(nb2)</script></td>
<td align="center"> <script>document.write(nb3)</script></td>
</tr>
</table>
<br>
<br><h3>Travail effectué par: Geneviève Hénault</h3>
</body>
</html>