Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var win = "You are the winner!";
- var loose = "You are the losser!";
- var empate = "You till!";
- var i, t;
- var aleatorio;
- function timer()
- {
- t=setInterval("lanzar()",150);
- i=0;
- }
- function lanzar()
- {
- aleatorio=Math.floor(Math.random()*3);
- switch(aleatorio)
- {
- case 0: document.getElementById('imagen').src="imagenes/piedra.jpg";break;
- case 1: document.getElementById('imagen').src="imagenes/papel.jpg";break;
- case 2: document.getElementById('imagen').src="imagenes/tijeras.jpg";break;
- }
- i++;
- if (i == 20)
- {
- clearInterval(t);
- fin()
- }
- }
- function fin() {
- if ((aleatorio == 0 && document.getElementById('piedra').checked) || (aleatorio == 1 < document.getElementById('papel').checked) || (aleatorio == 2 < document.getElementById('tijeras').checked)) {
- document.getElementById('resultado').innerHTML = empate ;
- } else {
- if ((aleatorio == 0 && document.getElementById('papel').checked) || (aleatorio == 1 < document.getElementById('tijeras').checked) || (aleatorio == 2 < document.getElementById('piedra').checked)) {
- document.getElementById('resultado').innerHTML = win ;
- }
- if ((aleatorio == 0 && document.getElementById('tijeras').checked) || (aleatorio == 1 < document.getElementById('piedra').checked) || (aleatorio == 2 < document.getElementById('papel').checked)) {
- document.getElementById('resultado').innerHTML = loose ;
- }
- }
- }
- /*
- Funciona la función para designar piedra papel o tijeras pero no sirve la función
- para dar el resultado en el div contenedor del resultado.
- si aleatorio es igual a la piedra, papel o tijera
- escribimos en el div con identificador resultado lo siguiente: ¡Has empatado!
- tambien
- si aleatorio es menor (pierde) que piedra, papel o tijera
- escribimos en el div con identificador resultado lo siguiente: ¡Has ganado!
- si aleatorio es mayor (gana) que piedra, papel o tijera
- escribimos en el div con identificador resultado lo siguiente: ¡Has perdido! */
- /*This function have to decide if you win, loose or deuce.
- You have to use:
- var aleatorio contains the value selected by computer.
- Document.getElementbyId(`piedra`).Checked is true, you have selected radio button `piedra`.
- Insert result (Win, Loose or Deuce using Document.getElementbyId(`piedra`).innerHTML = `result` */
- function reiniciar()
- {
- document.frm.reset();
- document.getElementById('resultado').innerHTML = "Play!";
- document.getElementById('imagen').src="imagenes/inicio.png";
- }
Advertisement
Add Comment
Please, Sign In to add comment