Nu game thanx to u


#1

I just replace the prompt for buttons and also fill some opstions about Scissors and after a quickly UI what I get is this. piedra, papel o tijera
Is in spanish because Im from Barcelona, I m thinking in extend it with lizard and spoke, also use some delay and kind of a roulette to show the cpu choice and maybe use green and red in case that u win or loose.


#2

It is really great! congrats to you for making it.


#3

Really nice work! Thanks for posting this!

Did you post the code somewhere and I'm missing it? It would be great for everyone to see the code you used.


#4

Hi pal,
Thanks 4 the interest _

The exercise is like this:

var usuarioElige = prompt("piedra, papel o tijera?");
var computadoraElige = Math.random();
if (computadoraElige <0.34){
    computadoraElige = "piedra";
}else if(computadoraElige <=0.67){
    computadoraElige = "papel";
}else{
    computadoraElige = "tijera";
}


var comparar= function(eleccion1,eleccion2){
    if(eleccion1===eleccion2){
        return "¡Es un empate!";
    }
    if(eleccion1==="piedra"){
        if(eleccion2==="tijera"){
            return "piedra gana";    
        }else{
            return "papel gana";
        }
    }else if(eleccion1 === "papel"){
        
        if(eleccion2 === "piedra"){
           return "papel gana"; 
        }
    }
}

comparar(usuarioElige,computadoraElige);

If u realize we need to fill a last option for scissors (tijeras),

U can see the changes here:

  • I finish the option tijeras.
  • Then coment the prompt and wrap the code into a new function yea()
  • dato is the param of yea so... in the HTML file I added onclick inside the buttons attaching a param to eachone, I mean paper (papel) button has onclick="yea('papel')" but honestly I dont like this way to do it, is quick but is dirty would be better not include js on the HTML and just give an #id to the buttons and then call them from the .js file in an event but I figure out this solution to do it fast.
    My intention is is rewrite it porperly soon an add some features like className to change the color of the text to green or red if u win or loose,
// var usuarioElige = prompt("piedra, papel o tijera?");

function yea(dato) {
  var usuarioElige = dato;
  var computadoraElige = Math.random();
  if (computadoraElige <0.34){
  	computadoraElige = "piedra";
  }else if(computadoraElige <=0.67){
  	computadoraElige = "papel";
  }else{
  	computadoraElige = "tijera";
  }


  var comparar= function(eleccion1,eleccion2){
      if(eleccion1===eleccion2){
          return "¡Es un empate!";
      }
      if(eleccion1==="piedra"){
          if(eleccion2==="tijera"){
              return "piedra gana";
          }else{
              return "papel gana";
          }
      }else if(eleccion1 === "papel"){
                if(eleccion2 === "piedra"){
                    return "papel gana";
                  }else{
                    return "tijera gana";
                    }
                }else if(eleccion1 === "tijera"){
                          if(eleccion2 === "piedra"){
                              return "gana piedra";
                            }else{
                              return "tijera gana";
                              }
                          }
                // ouyea
    };

  var solucion = comparar(usuarioElige,computadoraElige);

  console.log(solucion);
  document.getElementById("compu").innerHTML = " la compu elige " + computadoraElige;
  document.getElementById("este").innerHTML = solucion ;


}

I use a CDN link to fontAwesome to use the icons.
Creating a variable to store the solution function helpsme to print it into a div with inner, and also with the CPU choise as u can see "compu" and "este" are justs id´s of div
document.getElementById("compu").innerHTML = " la compu elige " + computadoraElige;
document.getElementById("este").innerHTML = solucion ;

U can have a look to my code including CSS in my gitHub repository https://github.com/padrisimo/piedra but be aware that I am still just an student so I m not the right person to learn from.

Kind Regards and sorry for my grammar :grinning:
Adrián Fernández aka @padrisimoCoder