Guest User

Piedra papel o tijera

a guest
Oct 3rd, 2010
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var win = "You are the winner!";
  2. var loose = "You are the losser!";
  3. var empate = "You till!";  
  4. var i, t;
  5. var aleatorio;
  6.  
  7.  
  8. function timer()
  9. {
  10.     t=setInterval("lanzar()",150);
  11.     i=0;
  12. }
  13. function lanzar()
  14. {
  15.     aleatorio=Math.floor(Math.random()*3);
  16.     switch(aleatorio)
  17.     {
  18.         case 0: document.getElementById('imagen').src="imagenes/piedra.jpg";break;
  19.         case 1: document.getElementById('imagen').src="imagenes/papel.jpg";break;
  20.         case 2: document.getElementById('imagen').src="imagenes/tijeras.jpg";break;
  21.     }
  22.     i++;
  23.  
  24.     if (i == 20)
  25.     {
  26.     clearInterval(t);
  27.       fin()
  28.     }
  29. }
  30. function fin() {
  31.   if ((aleatorio == 0 && document.getElementById('piedra').checked)  || (aleatorio == 1 < document.getElementById('papel').checked) || (aleatorio == 2 < document.getElementById('tijeras').checked)) {
  32. document.getElementById('resultado').innerHTML = empate ;
  33.             }  else {
  34.   if ((aleatorio == 0 && document.getElementById('papel').checked)  || (aleatorio == 1 < document.getElementById('tijeras').checked) || (aleatorio == 2 < document.getElementById('piedra').checked)) {
  35. document.getElementById('resultado').innerHTML = win ;
  36.             }
  37.   if ((aleatorio == 0 && document.getElementById('tijeras').checked)  || (aleatorio == 1 < document.getElementById('piedra').checked) || (aleatorio == 2 < document.getElementById('papel').checked)) {
  38. document.getElementById('resultado').innerHTML = loose ;
  39.             }
  40.         }
  41.     }
  42.             /* 
  43.     Funciona la función para designar piedra papel o tijeras pero no sirve la función
  44.     para dar el resultado en el div contenedor del resultado.      
  45.            
  46.     si aleatorio es igual a la piedra, papel o tijera
  47.           escribimos en el div con identificador resultado lo siguiente: ¡Has empatado!   
  48.             tambien
  49.     si aleatorio es menor (pierde) que piedra, papel o tijera
  50.           escribimos en el div con identificador resultado lo siguiente: ¡Has ganado!
  51.   si aleatorio es mayor (gana) que piedra, papel o tijera
  52.           escribimos en el div con identificador resultado lo siguiente: ¡Has perdido! */
  53.                
  54.     /*This function  have to decide if you win, loose or deuce.
  55.       You have to use:
  56. var aleatorio contains the value selected by computer.
  57. Document.getElementbyId(`piedra`).Checked is true, you have selected radio button `piedra`.
  58. Insert result (Win, Loose or Deuce using Document.getElementbyId(`piedra`).innerHTML = `result` */
  59.  
  60. function reiniciar()
  61. {
  62.     document.frm.reset();
  63.     document.getElementById('resultado').innerHTML = "Play!";
  64.     document.getElementById('imagen').src="imagenes/inicio.png";
  65. }
Advertisement
Add Comment
Please, Sign In to add comment