-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
65 lines (57 loc) · 1.76 KB
/
main.js
File metadata and controls
65 lines (57 loc) · 1.76 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
function getUserChoice (userInput) {
userInput = userInput.toLowerCase();
const validChoices = new Set(['rock', 'paper', 'scissors']);
if (validChoices.has(userInput)) {
return userInput;
} else {
return "Invalid choice! Please choose 'rock', 'paper', or 'scissors'.";
}
}
function getComputerChoice () {
const randomNumber = Math.floor(Math.random() * 3);
if (randomNumber === 0) {
return 'rock';
}
if (randomNumber === 1) {
return 'paper'
}
if (randomNumber === 2) {
return 'scissors';
}
}
function determineWinner (userChoice, computerChoice) {
if (userChoice === computerChoice) {
return 'The game is a tie!';
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'Computer wins!';
} else if (computerChoice === 'scissors') {
return 'You win!';
} }
if (userChoice === 'paper') {
if (computerChoice === 'rock') {
return 'You win!';
} else if (computerChoice === 'scissors') {
return 'Computer wins!';
} }
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'Computer wins!';
} else if (computerChoice === 'paper') {
return 'You wins!';
} }
if (userChoice === 'Bomb') {
return 'You win!';
}
}
const userChoice = getUserChoice('rock');
const computerChoice = getComputerChoice();
function playGame () {
var userChoice = getUserChoice('rock');
var computerChoice = getComputerChoice();
}
console.log('User\'s Choise:', userChoice);
console.log('Computer\'s Choice:', computerChoice);
console.log('Results:', determineWinner(userChoice,computerChoice));
playGame ()