-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMagic8Ball.js
48 lines (37 loc) · 1.04 KB
/
Magic8Ball.js
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
let userName ="";
userName ? console.log(`hello, ${userName}`): console.log('Hello!');
const userQuestion = console.log('Hello! ' +userName+ 'What is your question?');
/*
Math.random() returns a value between 0 (inclusive) and 1 (exclusive).
In order to make this set of numbers range from 0 (inclusive) to 8 (exclusive) we can multiple the returned value by 8.
Finally, to ensure we only have whole numbers from 0 to 7 we can round down using Math.floor().
*/
const randomNumber = Math.floor(Math.random()*8);
let eightBall = randomNumber;
switch (eightBall){
case 0:
eightBall = 'It is certain';
break;
case 1:
eightBall = 'It is decidedly so';
break;
case 2:
eightBall = 'Reply hazy try again';
break;
case 3:
eightBall = 'Cannot predict now';
break;
case 4:
eightBall = 'Do not count on it';
break;
case 5:
eightBall = 'My sources say no';
break;
case 6:
eightBall = 'Outlook not so good';
break;
case 7:
eightBall = 'Signs point to yes';
break;
}
console.log(`The eight ball answered: ${eightBall}.`);