This repository was archived by the owner on Oct 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy path3-magic-8-ball.js
More file actions
120 lines (90 loc) · 2.28 KB
/
3-magic-8-ball.js
File metadata and controls
120 lines (90 loc) · 2.28 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
Let's peer into the future using a Magic 8 Ball!
https://en.wikipedia.org/wiki/Magic_8-Ball
There are a few steps to being able view the future though:
* Ask a question
* Shake the ball
* Get an answer
* Decide if it's positive or negative
The question can be anything, but the answers are fixed,
and have different levels of positivity or negativity.
Below are the possible answers:
## Very positive
It is certain.
It is decidedly so.
Without a doubt.
Yes - definitely.
You may rely on it.
## Positive
As I see it, yes.
Most likely.
Outlook good.
Yes.
Signs point to yes.
## Negative
Reply hazy, try again.
Ask again later.
Better not tell you now.
Cannot predict now.
Concentrate and ask again.
## Very negative
Don't count on it.
My reply is no.
My sources say no.
Outlook not so good.
Very doubtful.
*/
// This should log "The ball has shaken!"
// and return the answer.
function shakeBall(answer) {
console.log("The ball has shaken!")
return "The ball has shaken!"
}
// The answer should come from shaking the ball
let answer = ["very positive", "positive", "negative", "very negative"];
// When checking the answer, we should tell someone if the answer is
// - very positive
// - positive
// - negative
// - very negative
function checkAnswer() {
for(let i=0;i<answer.length;i++)
return answer[i]
}
// console.log(answer[x])
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.
To run these tests type `node 3-magic-8-ball.js` into your terminal
*/
const log = console.log;
let logged;
console.log = function () {
log(...arguments);
logged = arguments[0];
};
function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}
logged = undefined;
console.log(`${test_name}: ${status}`);
}
const validAnswers = [];
function testAll() {
const answer = shakeBall();
test(
`shakeBall logs "The ball has shaken!"`,
logged === "The ball has shaken!"
);
test(`shakeBall returns an string answer"`, typeof answer === "string");
test(
`checkAnswer returns the level of positivity"`,
["very positive", "positive", "negative", "very negative"].includes(
checkAnswer(answer)
)
);
}
testAll();