-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
88 lines (72 loc) · 2.52 KB
/
script.js
File metadata and controls
88 lines (72 loc) · 2.52 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function getComputerChoice (){
const options = ["rock", "paper", "scissors"];
let choice = options[Math.floor(Math.random() * options.length)];
return choice;
}
//const rounds = 5
function playGame () {
/* Here Im importing the results of computerchoice function */
let humanScore = 0;
let computerScore = 0;
// How to tab a block of code in VSCode?
//Volver a usar playRound, hacer toda la monda dentro y hacer returns
function playRound (humanChoice) {
let humanPoints = document.getElementById("human-score");
let computerPoints = document.getElementById("computer-score");
let computerChoice = getComputerChoice();
if (humanChoice === computerChoice) {
console.log(humanScore);
console.log(computerScore);
} else if (
(humanChoice === "rock" && computerChoice === "scissors") ||
(humanChoice === "paper" && computerChoice === "rock") ||
(humanChoice === "scissors" && computerChoice === "paper")
) {
humanScore++;
console.log(humanScore);
console.log(computerScore);
humanPoints.textContent = humanScore;
} else {
computerScore++;
console.log(humanScore);
console.log(computerScore);
computerPoints.textContent = computerScore;
}
if (humanScore === 5) {
humanPoints.textContent = humanScore;
computerPoints.textContent = computerScore;
alert("You won the game!");
humanScore = 0;
computerScore = 0;
humanPoints.textContent = humanScore;
computerPoints.textContent = computerScore;
} else if (computerScore === 5) {
humanPoints.textContent = humanScore;
computerPoints.textContent = computerScore;
alert("You lost the game!");
humanScore = 0;
computerScore = 0;
humanPoints.textContent = humanScore;
computerPoints.textContent = computerScore;
}
}
document.addEventListener('DOMContentLoaded', function(event) {
const gameZone = document.getElementById("game");
gameZone.addEventListener('click', (event) => {
let target = event.target;
let result;
switch(target.id) {
case 'btn-rock':
result = playRound("rock");
break;
case 'btn-paper':
result = playRound("paper");
break;
case 'btn-scissors':
result = playRound("scissors");
break;
}
});
});
}
playGame ();