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
48 lines (43 loc) · 1.36 KB
/
script.js
File metadata and controls
48 lines (43 loc) · 1.36 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
//track previous guess
var correctGuesses = 0;
var main = function (input) {
var randomWord = calcRandomWord();
console.log(randomWord);
var myOutputValue = `You guessed this ${input}. We guessed this ${randomWord}. <br> Try again. <br>Correct Guesses: ${correctGuesses}. `;
// if correct guess
if (input == randomWord) {
// add to correct guess tracking
correctGuesses += 1;
console.log(correctGuesses);
if (correctGuesses == 1) {
return `You guessed this ${input}. We guessed this ${randomWord}.<br>You got it right.<br> Correct Guesses: ${correctGuesses}. <br> Guess one more correctly to win.`;
}
if (correctGuesses == 2) {
correctGuesses -= 2;
return `You guessed this ${input}. We guessed this ${randomWord}.<br>You won!`;
}
}
return myOutputValue;
};
// define secret words
var calcRandomNum = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal);
var randomNumber = randomInteger + 1;
return randomNumber;
};
// assign number values to secret words and generate random secret words
var calcRandomWord = function () {
var totalNumWords = 3;
var randomWord = calcRandomNum(totalNumWords);
if (randomWord == 1) {
return "banana";
}
if (randomWord == 2) {
return "chisel";
}
if (randomWord == 3) {
return "faucet";
}
return randomWord;
};