Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/01/2009, 12:40
MoonShadow
 
Fecha de Ingreso: enero-2008
Mensajes: 53
Antigüedad: 17 años
Puntos: 0
Respuesta: Problema Juego Del Dado

Código javascript:
Ver original
  1. <html>
  2. <head>
  3. <title></title>
  4. <body>
  5. <script type="text/javascript">
  6. var MAX = 10;
  7. var num_aleatorio = Math.round(Math.random()*(MAX));
  8. document.write(num_aleatorio);
  9.  
  10. opcion=prompt ("El siguiente numero será mayor o menor?(OPCIONES: mayor O menor)","");
  11.  
  12. var num_aleatorio2 = Math.round(Math.random()*(MAX));
  13.  
  14. if(opcion=="mayor")
  15. {
  16.     if(num_aleatorio>num_aleatorio2){
  17.         alert("ACERTASTE!!\n El numero: " + num_aleatorio + " es mas grande que: " + num_aleatorio2 + "");
  18.     }
  19.     else {
  20.         alert("FALLASTE!!!!\n El numero: " + num_aleatorio + " es mas pequeño que: " + num_aleatorio2 + "");
  21.     }
  22. }
  23.  
  24. else if(opcion=="menor"){
  25.     if(num_aleatorio<num_aleatorio2){
  26.         alert("ACERTASTE!!\n El numero: " + num_aleatorio + " es mas pequeño que: " + num_aleatorio2 + "");
  27.     }
  28.     else {
  29.         alert("FALLASTE!!!!\n El numero: " + num_aleatorio + " es mas grande que: " + num_aleatorio2 + "");
  30.     }
  31. }
  32. else {
  33.     alert("ERROR SINTAXYS!!!\n OPCIONES: mayor O menor");
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40. </script>
  41. </body>
  42. </html>

Ahí lo tienes.

Estabas generando mal el número, deberías hacerlo sólo una vez antes de las preguntas. Y también estabas comparando mal las condiciones. Preguntabas si
Código:
opcion==menor
, esa sería una comparación del tipo variable a variable. Para hacer una comparación por una cadena de caracteres, el valor tiene que ir entre comillas, por ejemplo:
Código:
opcion=="menor"
Espero te sirva.

Saludos