forked from rocketacademy/basics-github-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (48 loc) · 1.42 KB
/
script.js
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
var PassingMark = function () {
var randMark = Math.ceil(Math.random() * 3) + 1;
return randMark;
};
var Points = 0;
var WinCounter = PassingMark();
var WinCounter02 = WinCounter;
var main = function (input) {
var ComputerWords = "a";
console.log(ComputerWords);
var myOutputValue = "Please continue guessing.";
if (ComputerWords == input && WinCounter == 1) {
return `Congratulations you guessed it right ${WinCounter02} times! The game will end.`;
}
if (ComputerWords != input) {
WinCounter = WinCounter + Points;
Points = 0;
myOutputValue = "Sorry! You're back to square one. Please try again.";
}
if (ComputerWords == input) {
WinCounter = WinCounter - 1;
Points = Points + 1;
myOutputValue = "Congratulations you guessed it right!";
}
console.log(`WinCounter ${WinCounter}.`);
console.log(`Points ${Points}`);
return myOutputValue;
};
//If the computer != players input & the score equals to one, player loses 1 point.
//Three secret words: banana, chisel and faucet.
//Player must guess correctly twice in total.
//Use dice roll to determine the computer choice.
var RollDice = function () {
var randNumber = Math.ceil(Math.random() * 3);
return randNumber;
};
var WordChoice = function () {
var Computerchoice = RollDice();
if (Computerchoice == 1) {
return "banana";
}
if (Computerchoice == 2) {
return "chisel";
}
if (Computerchoice == 3) {
return "faucet";
}
};