forked from rocketacademy/basics-github-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (67 loc) · 2.01 KB
/
script.js
File metadata and controls
71 lines (67 loc) · 2.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
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
//To win the game the player must guess correctly twice in total, e.g. the player still wins if she guesses wrongly 1 or more times between her 2 correct guesses.
//For each guess, output all information such as the guessed word, the secret word, and how many correct guesses the player still needs until she wins.
var winCount = 0;
var correctNeeded = 2;
var playerCount = 0;
var main = function (input) {
playerCount = playerCount + 1;
var guessedWord = input;
console.log("Guessed Word:", guessedWord);
console.log("Numbers of Correct Guessed Needed:", correctNeeded);
var secretNumber = generateNumber();
var secretWord = generateSecretWord(secretNumber);
console.log("Secret Word:", secretWord);
var myOutputValue =
"You lose! You guessed " +
guessedWord +
" and the secret word is " +
secretWord +
". You need " +
correctNeeded +
" more guesses to win.";
if (guessedWord == secretWord && winCount != 2) {
winCount = winCount + 1;
correctNeeded = correctNeeded - winCount;
myOutputValue =
"You win! You guessed " +
guessedWord +
" and the secret word is " +
secretWord +
". You still need " +
correctNeeded +
" more guess to win.";
}
if (guessedWord == secretWord && winCount == 2) {
winCount = winCount + 1;
correctNeeded = correctNeeded - winCount;
myOutputValue =
"You have won the game in " +
playerCount +
" tries! You guessed " +
guessedWord +
" and the secret word is " +
secretWord +
".";
}
return myOutputValue;
};
//Number Generator
var generateNumber = function (max) {
var max = 3;
var estRandomNumber = Math.random() * max;
var randomInteger = Math.floor(estRandomNumber);
var randomNumber = randomInteger + 1;
return randomNumber;
};
//Secret Word Generator
var generateSecretWord = function (inputNumber) {
if (inputNumber == 1) {
return "banana";
}
if (inputNumber == 2) {
return "chisel";
}
if (inputNumber == 3) {
return "faucet";
}
};