JavaScript - como hacer repita varias funciones si su resultado son iguales

 
Vista:
sin imagen de perfil

como hacer repita varias funciones si su resultado son iguales

Publicado por liantony (7 intervenciones) el 26/12/2016 14:59:42
buenas , quisiera saber si puedo hacer que se repita varias funciones si su resultado son iguales ,.




Screen_Shot_2016_12_24_at_3_02_26_PM

en la imagen se ve que se repite el 38 dos veces una forma de que si sucede eso vuelva a repetir la funcion


este es el codigo que utilizo


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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
 
	<title>numeror aleatorios </title>
 
</head>
 
 
<body>
<p>generar  4 numero_ entre  1 y 47 .</p>
 
 
 
<buttononclick="ejecutarDosFunciones()"    ;  >Try it</button>
 
<pid="demo_1"></p>
<pid="demo_2" ></p>
<pid="demo_3" ></p>
<pid="demo_4"></p>
 
 
<scripttype="text/javascript">
 
 
functionejecutarDosFunciones()
{
	myFunction_1();
	myFunction();	// body...
}
 
functionmyFunction_1() {
	for( var numero = 3; numero <= 4 ; numero ++ )
	{
		var x = document.getElementById("demo_"+numero );
		x.innerHTML = "";
		for (var i = 0; i < 4; i++) {
			var y = Math.ceil((Math.random()* 39.51 + 7.49 / 20 ));
			x.innerHTML += y + " ";
		}
	} // body...
}
 
functionmyFunction() {
  for(var n = 1; n <= 2; n++) {
    var e = document.getElementById("demo_"+n);
    e.innerHTML = "";
    for(var i = 0; i < 4; i++) {
      var r = Math.floor((Math.random() *  39.51) + 7.49 );
      e.innerHTML += r + " ";
    }
  }
}
 
 
</script>
 
</body>
 
 
</html>
 
<code>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro
Val: 1.448
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

como hacer repita varias funciones si su resultado son iguales

Publicado por Alejandro (532 intervenciones) el 27/12/2016 19:19:25
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
Crea una arreglo y si el numero generado existe en el arreglo repite el proceso de lo contrario almacenalo en el arreglo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Alejandro
Val: 1.448
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

como hacer repita varias funciones si su resultado son iguales

Publicado por Alejandro (532 intervenciones) el 27/12/2016 20:02:13
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
	<head>
		<title>numeror aleatorios </title>
		<script type="text/javascript">
			var arreglo=[];
 
			function ejecutarDosFunciones()
			{
				arreglo = [];
				myFunction_1();
				myFunction();	// body...
			}
 
			function myFunction_1()
			{
				for( var numero = 3; numero <= 4 ; numero ++ )
				{
					var x = document.getElementById("demo_"+numero );
					x.innerHTML = "";
 
					for (var i = 0; i < 4; i++) {
						do{
							var y = Math.ceil((Math.random()* 39.51 + 7.49 / 20 ));
						}while (arreglo.indexOf(y)>=0);
						arreglo.push(y);
						pad="00";
						y = pad.substr((y.toString()).length) + y
						x.innerHTML += y + " ";
					}
				} // body...
			}
 
			function myFunction() {
				for(var n = 1; n <= 2; n++)
				{
					var e = document.getElementById("demo_"+n);
					e.innerHTML = "";
					for(var i = 0; i < 4; i++) {
						do{
							var r = Math.floor((Math.random() *  39.51) + 7.49 );
						}while (arreglo.indexOf(r)>=0);
						arreglo.push(r);
						pad="00";
						r = pad.substr((r.toString()).length) + r
						e.innerHTML += r + " ";
					}
				}
			}
		</script>
		<style>
			p[id^='demo_'] {font-family: monospace;}
		</style>
	</head>
 
	<body>
		<p>generar  4 numero_ entre  1 y 47 .</p>
		<button onclick="ejecutarDosFunciones()"      >Try it</button>
 
		<p id="demo_1"></p>
		<p id="demo_2"></p>
		<p id="demo_3"></p>
		<p id="demo_4"></p>
	</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

como hacer repita varias funciones si su resultado son iguales

Publicado por liantony (7 intervenciones) el 28/12/2016 00:56:50
no se me ocurrio esa manera gracias , soy nuevo en esto del js grasias ............
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar