-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagic Eighr ball.html
More file actions
107 lines (95 loc) · 2.52 KB
/
Magic Eighr ball.html
File metadata and controls
107 lines (95 loc) · 2.52 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
<!-- /*In this project I built a Magic Eight Ball using control flow in JavaScript.
A user's able to input a question, then the program will output a random fortune.*/ -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magic Eight Ball</title>
<style>
body {
font-family: 'Arial', sans-serif;
text-align: center;
margin: 0;
padding: 0;
}
.container {
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
max-width: 500px;
margin: 200px auto;
padding: 20px;
}
h1 {
color: #4a90e2;
}
p {
color: #333;
font-size: 18px;
}
.eightball-answer {
margin-top: 20px;
padding: 15px;
background-color: #e0f7fa;
border-radius: 8px;
color: #00796b;
font-weight: bold;
font-size: 20px;
}
.question {
color: #5c6bc0;
font-style: italic;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Magic Eight Ball</h1>
<p id="greeting"></p>
<p class="question" id="user-question"></p>
<div class="eightball-answer" id="eightball-answer"></div>
</div>
<script>
var userName = prompt("Enter your name");
let userQuestion = prompt("Enter your question");
let greetingText = userName ? `Hello, ${userName}!` : 'Hello!';
document.getElementById('greeting').innerHTML = greetingText;
let questionText = `${userName} asked... "${userQuestion}" ?`;
document.getElementById('user-question').innerHTML = questionText;
let randomNumber = Math.floor(Math.random() * 8);
let eightBall = '';
switch (randomNumber) {
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;
default:
eightBall = 'You are unfortunate!';
break;
}
document.getElementById('eightball-answer').innerHTML = `The Magic Eight Ball's answer is... "${eightBall}"`;
</script>
</body>
</html>