How to show the result of a conditional structure of Java Script in a text box in html using jquery?

0
  var textoUser = $("#txtFieldUser");
  var textoGanhador = $("txtFieldGanhador");


  var computerChoice = Math.random();

  if (computerChoice < 0.34) {
        computerChoice = "Pedra";

  } else if(computerChoice <= 0.67) {
        computerChoice = "Papel";
  } else {
        computerChoice = "Tesoura";
  } 

  console.log("Computer: " + computerChoice);

  var compare = function (choice1, choice2) {
      if (choice1 === choice2)
        return ("O resultado é um empate!");
      else if (choice1 === "pedra") {
      if (choice2 === "tesoura")
            return ("pedra vence");
        else {
            return ("papel vence");
        }
    }
    else if (choice1 === "papel") {
        if (choice2 === "pedra")
            return "papel vence";
        else {
            return "tesoura vence";
        }
    }
    else if (choice1 === "tesoura") {
        if (choice2 === "pedra")
            return "pedra vence";
        else {
            return "tesoura vence";
        }
    }
};


    compare(textoUser, computerChoice);
   $('#txtFieldComputer').ready(function() {
       $('#txtFieldComputer').val(computerChoice);
   });
    
asked by anonymous 21.10.2017 / 02:00

0 answers