-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
67 lines (50 loc) · 1.89 KB
/
Copy pathjavascript.js
File metadata and controls
67 lines (50 loc) · 1.89 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
/*Part 1: computer randomise choice or Rock, Paper, Scissors.
Complete. */
let choice = Math.floor(Math.random() * 100) + 1;
function getComputerChoice() {
const a = 'Rock';
const b = 'Paper';
const c = 'Scissors';
let result;
if (choice <= 33) {
result = a;
} else if (choice > 33 && choice <= 66) {
result = b;
} else {
result = c;
}
return result
}
const computer = getComputerChoice();
let playerChoice = prompt("Enter your choice of rock, paper, or scissors");
let player = playerChoice.toLowerCase();
let comScore = 0;
function playRound() {
if (player == "rock" && computer == "Rock") {
return "It's a draw! both chose Rock";
} else if (player == "scissors" && computer == "Rock") {
comScore = ++comScore;
return "You lose! rock beats scissors";
} else if (player == "scissors" && computer == "Paper") {
return "You win! scissors beats paper";
} else if (player == "rock" && computer == "Scissors") {
return "You win! rock beats scissors";
} else if (player == "rock" && computer == "Paper") {
return "You lose! Paper beats rock";
} else if (player == "scissors" && computer == "Scissors") {
return "Its a draw! Both chose scissors";
} else if (player == "paper" && computer == "Paper") {
return "It's a draw! Both chose paper";
} else if (player == "paper" && computer == "Scissors") {
return "You lose! scissors beats paper";
} else if (player == "paper" && computer == "Rock") {
return "You win! paper beats rock";
} else {
console.log("Try again. please only input either Rock, Paper, or Scissors!");
}
}
function game() {
console.log(playRound(player, computer));
console.log(getComputerChoice());
}
console.log(game() `current score is ${comScore}.`);