-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaper.js
More file actions
63 lines (55 loc) · 1.67 KB
/
Copy pathpaper.js
File metadata and controls
63 lines (55 loc) · 1.67 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
function checkPaper(p) {
// Importing elements needed for modifications
let userScore = document.getElementById("userscore");
let computerScore = document.getElementById("computerscore");
let scoreAlertBox = document.getElementById("scorealert");
let playerName = document.getElementById("playername");
let restartbtn = document.getElementById("restart");
// Pre modifications
restartbtn.style.display = "block";
// Scores
let uScore = 0;
let cScore = 0;
// Make random number for computer choice
let min = 1;
let max = 3;
let computerChoice = Math.floor(Math.random() * (max - min + 1)) + min;
// Get user's choice and compare
let userChoice = document.querySelector("p");
userChoice = userChoice.innerHTML;
// Comparison
if (userChoice === "Paper" && computerChoice === 2) {
scoreAlertBox.style.display = "block";
scoreAlertBox.innerHTML = "A Tie Game 😮";
setTimeout(function() {
scoreAlertBox.style.display = "none";
}, 1500)
}
else if (userChoice === "Paper" && computerChoice === 1) {
userScore.innerHTML++;
} else {
computerScore.innerHTML++;
}
// Check if the game is over
//Checking if player won
if (userScore.innerHTML >= 5) {
board.style.visibility = "visible";
board.innerHTML = "Game Over! 🎮 " + "<br>" + "You won 🎉🎉";
setTimeout(function() {
location.reload();
}, 5000)
}
else {
// Do nothing
}
// Checking if computer won
if (computerScore.innerHTML >= 5) {
board.style.visibility = "visible";
board.innerHTML = "Game over! 🎮" + "<br>" + "You lose 😣😣";
setTimeout(function() {
location.reload();
}, 5000)
} else {
// Do nothing
}
}