amorz of Takties
8/24/2016 - 11:31 AM

Rock paper scissors

Rock paper scissors

     var userChoice = prompt("Do you choose rock, paper or scissors?");

var computerChoice = Math.random()
if(computerChoice < 0.34) {
    computerChoice = "rock";
}
else if (computerChoice <= 0.67) {
    computerChoice = "paper";
}
else {
    computerChoice = "scissors";
}

function compare(choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
    else if(choice1 === 'rock') {
        if (choice2 === 'scissors') {
            return "Computers wins";
        }
        else {
            return "You win!";
        }
    }
    else if(choice1 === 'paper') {
        if (choice2 === 'rock') {
            return "Computers wins";
        }
        else {
            return "You win!";
        }
    }
    else if(choice1 === 'scissors') {
        if (choice2 === 'rock') {
            return "Computers wins";
        }
        else {
            return "You win!";
        }
    }
};

function consoleResult(obj) {
  console.group('result');
  console.log('Computer: ', obj.computer);
  console.log('User: ', obj.user);
  console.log('Result: ', obj.result);
  console.groupEnd();
}
var result = compare(userChoice,computerChoice)

consoleResult({"user":userChoice,"computer":computerChoice,"result":result});