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
41 lines (37 loc) · 1.3 KB
/
script.js
File metadata and controls
41 lines (37 loc) · 1.3 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
var winCounter = 0;
var roundCounter = 1;
var main = function (input) {
var secretWord = randomWord();
var myOutputValue = `Round ${roundCounter}<br><br>You guessed ${input}. The secret word was ${secretWord}.`;
myOutputValue += `<br>Sorry you picked the wrong word. You have guessed correctly ${winCounter} time(s).<br>${
2 - winCounter
} more to go!`;
if (input == secretWord) {
winCounter = winCounter + 1;
myOutputValue = `Round ${roundCounter}<br><br>You guessed ${input}. The secret word was ${secretWord}.`;
myOutputValue += `<br>That's right! You have guessed correctly ${winCounter} time(s).<br>${
2 - winCounter
} more to go!`;
if (winCounter == 2) {
myOutputValue = `Round ${roundCounter}<br><br>You guessed ${input}. The secret word was ${secretWord}.`;
myOutputValue += `<br>That's right!<br><br>You've won this round! Let's start a new round...`;
roundCounter = roundCounter + 1;
winCounter = 0;
}
}
return myOutputValue;
};
var randomWord = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal);
if (randomInteger == 0) {
var secret = "banana";
}
if (randomInteger == 1) {
var secret = "chisel";
}
if (randomInteger == 2) {
var secret = "faucet";
}
return secret;
};