Réaliser une boucle pour obtenir plusieurs résultat ...

Résolu
popy29 Messages postés 6 Date d'inscription mardi 19 octobre 2004 Statut Membre Dernière intervention 22 mai 2007 - 28 août 2005 à 23:05
popy29 Messages postés 6 Date d'inscription mardi 19 octobre 2004 Statut Membre Dernière intervention 22 mai 2007 - 29 août 2005 à 11:53
bonjour,

je cherche à obtenir plusieurs résultats ou n résultat différents à partir d'une fonction mais je ne trouve pas comment faire pour la boucle.

voici le code :
***********************************************************************************
<html>
<head>
<title></title>
</head>




<script>
function genere()
{



var a = Math.round(Math.random()*48+1);
var b = Math.round(Math.random()*48+1);
var c = Math.round(Math.random()*48+1);
var d = Math.round(Math.random()*48+1);
var e = Math.round(Math.random()*48+1);
var f = Math.round(Math.random()*48+1);


var x = new Array ( a,b,c,d,e,f);

if((x[0] == x[1]) || (x[0] == x[2]) || (x[0] == x[3]) || (x[0] == x[4]) || (x[0] == x[5]) ||
(x[1] == x[2]) || (x[1] == x[3]) || (x[1] == x[4]) || (x[1] == x[5]) ||
(x[2] == x[3]) || (x[2] == x[4]) || (x[2] == x[5]) ||
(x[3] == x[4]) || (x[3] == x[5]) ||
(x[4] == x[5]) || (x[5] == x[4]))

genere();

n1=x[0];
n2=x[1];
n3=x[2];
n4=x[3];
n5=x[4];
n6=x[5];

if ((n1==n2 || n1==n3 || n1==n4 || n1==n5 || n1==n6
|| n2==n3 || n2==n4 || n2==n5 || n2==n6
|| n3==n4 || n3==n5 || n3==n6
|| n4==n5 || n4==n6
|| n5==n6))
{
genere();
}
else
{
affich= a+" "+b+" "+c+" "+d+" "+e+" "+f ;
document.getElementById("resul1").innerHTML= affich;
}

}

</script>



<form name='f'>
</form>


</html>
*************************************************************************
merci d'avance

2 réponses

jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 29
29 août 2005 à 01:32
c'est quoi le but du jeu ? d'avoir 6 nombres distinct compris entre 1 et 48 ?

Je crois que cette source : http://www.javascriptfr.com/code.aspx?ID=33426 devrait t'aider ...

if
(!
Array
.prototype.sortRandom)
Array
.prototype.sortRandom =
function
() {
this
.
sort
(
function
(elmt1, elmt2) {
return
((2 *
Math
.
round
(
Math
.
random
())) - 1) }); }

function truc()
{
var t = new Array();
for (i = 0; i < 48; i++)
t[i] = i + 1;

t.sortRandom();

return t[0] + ' ' + t[1] + ' ' + t[2] + ' ' t[3] + ' ' + t[4] + ' ' + t[5];
}

document.getElementById("resul1").innerHTML= truc();



<HR>



Cyril - MCP ASP.net
Webmaster de : Hoshimi.CodeS-SourceS.fr
3
popy29 Messages postés 6 Date d'inscription mardi 19 octobre 2004 Statut Membre Dernière intervention 22 mai 2007
29 août 2005 à 11:53
ok merci pour ton aide
0
Rejoignez-nous