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
60 lines (49 loc) · 1.2 KB
/
script.js
File metadata and controls
60 lines (49 loc) · 1.2 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
// Function
var random_Number = function () {
var randomNumber = Math.random() * 3;
// range from 0 to 2
var integernumber = Math.floor(randomNumber);
// range from 2 to 4
var number = integernumber + 2;
return number;
};
var counter = 0;
var round = random_Number();
console.log(round);
var main = function (input) {
var myOutputValue = "";
var computer_choice = secret_word();
console.log(computer_choice);
if (input == computer_choice) {
counter += 1;
myOutputValue = "You guessed it correctly " + counter + " time(s)";
} else {
counter = 0;
myOutputValue =
"You guessed it wrongly! " + counter + " time(s) correctly.";
}
if (counter == round) {
myOutputValue = `You win! You guessed it correctly ${counter} time(s)`;
}
return myOutputValue;
};
var rollRandom = function () {
var randomNumber = Math.random() * 3;
var integernumber = Math.floor(randomNumber);
var choices = integernumber + 1;
return choices;
};
var secret_word = function () {
var choice = rollRandom();
var word = "";
if (choice == 1) {
word = "banana";
}
if (choice == 2) {
word = "chisel";
}
if (choice == 3) {
word = "faucet";
}
return word;
};