-
-
Save MihailoJoksimovic/e619fbaf06d3a244bfe4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var userChoice = ["paper", "rock", "scissors"]; | |
var computerChoice = Math.random(); | |
if (computerChoice < 0.34) { | |
computerChoice = userChoice[1]; | |
} else if(computerChoice <= 0.67) { | |
computerChoice = userChoice[0]; | |
} else { | |
computerChoice = userChoice[2]; | |
} console.log("Computer: " + computerChoice); | |
var compare= function (choice1, choice2) { | |
if (choice1 === choice2) { | |
return "The result is a tie!"; | |
} | |
else if (choice1===userChoice[1]) { | |
if (choice2===userChoice[2]) { | |
return "You win!"; | |
} | |
else { | |
return "You lose!"; | |
} | |
} else if (choice1===userChoice[0]) { | |
if (choice2===userChoice[1]) { | |
return "You win!"; | |
} else { | |
return "You lose!" | |
} | |
} else if (choice1===userChoice[2]) { | |
if (choice2===userChoice[0]) { | |
return "You win!"; | |
} else { | |
return "You lose!"; | |
}; | |
}; | |
}; | |
var result = compare(userChoice, computerChoice); | |
console.log(result); | |
var play =function(choice) { | |
document.getElementById('computer-choice').innerHTML = computerChoice; | |
document.getElementById('user-choice').innerHTML = userChoice[choice]; | |
document.getElementById('result').innerHTML = result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment