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
52 lines (46 loc) · 1.6 KB
/
script.js
File metadata and controls
52 lines (46 loc) · 1.6 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
var correctGuessCount = 0;
var main = function (input) {
var randomNumber = randomNumGenerator();
console.log(randomNumber);
var secretWord = secretWordGenerator(randomNumber);
console.log(secretWord);
var result = evaluateResult(input, secretWord);
var myOutputValue = "";
if (correctGuessCount == 2) {
correctGuessCount = 0;
myOutputValue = `You guessed ${input} and the secret word was ${secretWord}. <br> <br> ${result} <br><br> Congrats, you have managed to get 2 correct guesses! Let's play again!`;
return myOutputValue;
}
var remainingCorrectGuess = 2 - correctGuessCount;
myOutputValue = `You guessed ${input} and the secret word was ${secretWord}. <br> <br> ${result} <br> <br> You still need ${remainingCorrectGuess} correct guess in order to win.`;
return myOutputValue;
};
//to evaluate if the user guess correctly
var evaluateResult = function (userGuess, secretWord) {
if (userGuess == secretWord) {
correctGuessCount++;
return "You guess correctly!";
}
return "That was an incorrect guess!";
};
//to determine the secret word for this round
var secretWordGenerator = function (randomNum) {
if (randomNum == 1) {
return "banana";
}
if (randomNum == 2) {
return "chisel";
}
if (randomNum == 3) {
return "faucet";
}
};
//to randomly generate a number from 1 to 3
var randomNumGenerator = function () {
//Math.random generate a decimal from 0 to 1
var randomDecimal = Math.random() * 3;
//Math.floor round the number down to an integer
var randomInteger = Math.floor(randomDecimal);
var diceNumber = randomInteger + 1;
return diceNumber;
};