-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (31 loc) · 1.01 KB
/
Copy pathscript.js
File metadata and controls
38 lines (31 loc) · 1.01 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
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
const generateTarget = () => {
return Math.floor(Math.random() * 10);
}
// Gives a target number between 0 and 9
const compareGuesses = (humanGuess, computerGuess, targetGuess) => {
if (Math.abs(humanGuess - targetGuess) > Math.abs(computerGuess - targetGuess)) {
return true;
};
if (Math.abs(humanGuess - targetGuess) < Math.abs (computerGuess - targetGuess)) {
return false;
};
}
// Determines winner based on closest guess to target
const updateScore= (winner) => {
if (winner === 'human') {
humanScore ++;
} else if (winner === 'computer') {
computerScore ++;
}
};
// Updates score after win
const advanceRound = () => currentRoundNumber ++;
// Updates the round number after each round.
updateScore('human');
console.log(humanScore);
// To confirm that this value increased by 1
updateScore('computer');
console.log(computerScore); // To confirm that this value increased by 1