Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ICON = {
- 'tie': 'info',
- 'loss': 'error',
- 'win': 'success'
- }
- $(function() {
- $('.gameicons > i').click(function(e) {
- // Getting user choice
- var userPick = $(e.currentTarget).data('val')
- console.log(userPick)
- //Deciding computer choice
- var computerChoice = Math.random();
- if (computerChoice < 0.34) {
- computerChoice = "rock";
- } else if (computerChoice <= 0.67) {
- computerChoice = "paper";
- } else {
- computerChoice = "scissors";
- }
- var win = decideWinner(userPick, computerChoice)
- swal(win, "The computer chose " + computerChoice, ICON[win])
- })
- })
- function decideWinner(user, bot) {
- switch (user) {
- case "paper":
- if (bot == "paper") return 'tie'
- if (bot == "scissors") return 'loss'
- if (bot == "rock") return 'win'
- break
- case "rock":
- if (bot == "paper") return 'loss'
- if (bot == "scissors") return 'win'
- if (bot == "rock") return 'tie'
- break
- case "scissors":
- if (bot == "paper") return 'win'
- if (bot == "scissors") return 'tie'
- if (bot == "rock") return 'loss'
- break;
- default:
- return 'An Error Occured'
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement