-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
110 lines (88 loc) · 3.68 KB
/
Copy pathapp.js
File metadata and controls
110 lines (88 loc) · 3.68 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//let user pick from the three options
let userScore = 0;
let computerScore = 0;
let userChoiceDisplay = document.getElementById('user-choice');
let computerChoice = document.getElementById('computer-choice');
let resultShown = document.getElementById('result');
// console.log(`${userChoice}`)
const rock = document.getElementById('rock');
const paper = document.getElementById('paper');
const scissor = document.getElementById('scissor');
rock.addEventListener('click', () => {
const userChoice = 'rock';
userChoiceDisplay.innerHTML = "Rock";
let choices = ['rock', 'paper', 'scissor'];
let computerPicked = choices[Math.floor(Math.random() * 3)];
computerChoice.innerHTML = computerPicked;
if (userChoice === "rock" && computerPicked === "paper") {
computerScore++;
resultShown.innerHTML = "You lost.";
}
if (userChoice === "rock" && computerPicked === "scissor") {
userScore++;
resultShown.innerHTML = "You won!";
}
if (userChoice === "rock" && computerPicked === "rock") {
resultShown.innerHTML = "Its a tie.";
}
updateScoreboard();
});
paper.addEventListener('click', () => {
const userChoice = 'paper';
userChoiceDisplay.innerHTML = "Paper";
let choices = ['rock', 'paper', 'scissor'];
let computerPicked = choices[Math.floor(Math.random() * 3)];
computerChoice.innerHTML = computerPicked;
if (userChoice === "paper" && computerPicked === "paper") {
resultShown.innerHTML = "Its a tie.";
}
if (userChoice === "paper" && computerPicked === "scissor") {
computerScore++;
resultShown.innerHTML = "You lost.";
}
if (userChoice === "paper" && computerPicked === "rock") {
userScore++;
resultShown.innerHTML = "You won!";
}
updateScoreboard();
});
scissor.addEventListener('click', () => {
const userChoice = 'scissor';
userChoiceDisplay.innerHTML = "Scissor";
let choices = ['rock', 'paper', 'scissor'];
let computerPicked = choices[Math.floor(Math.random() * 3)];
computerChoice.innerHTML = computerPicked;
if (userChoice === "scissor" && computerPicked === "paper") {
userScore++;
resultShown.innerHTML = "You won!";
}
if (userChoice === "scissor" && computerPicked === "scissor") {
resultShown.innerHTML = "Its a tie.";
}
if (userChoice === "scissor" && computerPicked === "rock") {
computerScore++;
resultShown.innerHTML = "You lost.";
}
updateScoreboard();
});
function updateScoreboard() {
document.getElementById("userScore").textContent = userScore;
document.getElementById("computerScore").textContent = computerScore;
}
// //when user clicks on an image the computer will display what the user choose
// // In the generator of whether user or computer picks one or another then there needs to be
// // a place where it can generate a random generator.
// //then this will trigger the computer to generate its own choice
// // then it will decided on whether the user or computer won. And if there is a tie the computer will display a log box with a its a tie.
// // which will then prompt the user to click ok. taking it back to the home page.
// //display the users choice on screen
// //calculate the option for the computer
// //decide who won based on users choice and computer choice
// //inputs the answer
// //computer calculates an answer
// //results on who won?
//play again
//*******score board will mark place a tally mark on either computer or user board***
//This would be a container with a numbers generating on if the user won it would show. etc.
//arrow on the right hand side
//create a variable one for computer or users score//