-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
74 lines (62 loc) · 2.65 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
let elemento = document.getElementById('btn')
elemento.addEventListener('click', function () {
var player_score = 0;
var computer_score = 0;
for (let i = 0; i < 5; i++) {
// your code here!
function computerChoice() {
const rps = ['rock', 'paper', 'scissors']
const random = Math.floor(Math.random() * 3);
return rps[random]
};
function playerChoice() {
choice = prompt('Hi, welcome to Rock-Paper-Scissors. Choose one: Paper, Rock or Scissors')
return choice.toLowerCase()
}
let computer = computerChoice()
let player = playerChoice()
switch (true) {
case player === 'paper' && computer === 'rock':
console.log(`Computer choose ${computer}. You win`);
player_score = player_score + 1
break;
case player === 'paper' && computer === 'scissors':
computer_score = computer_score + 1
console.log(`Computer choose ${computer}. You lose`);
break;
case player === 'scissors' && computer === 'rock':
computer_score = computer_score + 1
console.log(`Computer choose ${computer}. You lose`);
break;
case player === 'scissors' && computer === 'paper':
player_score = player_score + 1
console.log(`Computer choose ${computer}. You win`);
break;
case player === 'rock' && computer === 'scissors':
player_score = player_score + 1
console.log(`Computer choose ${computer}. You win`);
break;
case player === 'rock' && computer === 'paper':
computer_score = computer_score + 1
console.log(`Computer choose ${computer}. You lose`);
break;
case player === computer:
console.log(`Computer also choose ${computer}. It is a draw`);
break;
default:
console.log('Please try again.')
};
if (i === 4) {
if (computer_score > player_score) {
console.log(`Computer score ${computer_score} wins and you only ${player_score}. You lose :(`)
} else if (computer_score < player_score) {
console.log(`Computer score ${computer_score} wins and you ${player_score}. You win!`)
} else if (computer_score == player_score) {
console.log('It\'s a draw')
}
else {
console.log("Something went wrong")
}
}
}
})