Skip to content

Commit f5b7dd5

Browse files
Magic 8 Ball Game
1 parent 7fac8a9 commit f5b7dd5

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>MAGIC 8 BALL</title>
5+
6+
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,700|Montserrat:400,700' rel='stylesheet' type='text/css'>
7+
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js'></script>
8+
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
9+
10+
<link rel="stylesheet" type="text/css" href="style.css">
11+
</head>
12+
13+
<body>
14+
<div class="page">
15+
16+
<header>
17+
<h1>MAGIC <span>8</span> BALL</h1>
18+
</header>
19+
20+
<div class="ball" style="position:relative; width:80%" >
21+
22+
<p id="answer" class="answer">
23+
THIS IS WHERE THE ANSWER GOES
24+
</p>
25+
26+
<img id="8ball" src="https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/magic8ballQuestion.png" alt="Magic 8 Ball">
27+
28+
</div>
29+
30+
<br><br>
31+
32+
<div class="button" style="position:relative; width:80%">
33+
<button id="questionButton">ASK ME ANYTHING </button>
34+
</div>
35+
36+
<footer>
37+
<p>&copy; Skillcrush 2016</p>
38+
</footer>
39+
40+
41+
<script type="text/javascript" src="script.js"></script>
42+
43+
</div>
44+
</body>
45+
46+
</html>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
$(document).ready(function() {
2+
3+
var magic8Ball = {};
4+
magic8Ball.listOfAnswers = ["No", "Yes", "I don't think so...", "Of course!", "Indubitably", "In your dreams."];
5+
6+
$("#answer").hide();
7+
8+
magic8Ball.askQuestion = function(question) {
9+
$("#8ball").effect("shake");
10+
11+
$("#8ball").attr("src", "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/magic8ballAnswer.png");
12+
13+
$("#answer").fadeIn(4000);
14+
15+
var randomNumber = Math.random();
16+
17+
var randomNumberForListOfAnswers = randomNumber * this.listOfAnswers.length;
18+
19+
var randomIndex = Math.floor(randomNumberForListOfAnswers);
20+
21+
var answer = this.listOfAnswers[randomIndex];
22+
23+
$("#answer").text(answer);
24+
25+
console.log(question);
26+
console.log(answer);
27+
};
28+
29+
var onClick = function() {
30+
31+
$("#answer").hide();
32+
33+
$("#8ball").attr("src", "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/magic8ballQuestion.png");
34+
35+
36+
setTimeout(function(){
37+
var question = prompt("ASK A YES/NO QUESTION!");
38+
magic8Ball.askQuestion(question);
39+
}, 500);
40+
41+
42+
};
43+
44+
$("#questionButton").click(onClick);
45+
46+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
body {
2+
font-family: "Montserrat", sans-serif;
3+
color: #454545;
4+
margin: 0px;
5+
padding: 0px;
6+
background-color: #f8f8f8;
7+
background-image: url('bkgd2.png');
8+
}
9+
.page {
10+
width: 80%;
11+
max-width: 960px;
12+
margin: 0 auto;
13+
}
14+
.ball, .button {
15+
margin: 0 auto;
16+
}
17+
.answer {
18+
position:absolute;
19+
width:14%;
20+
top:50%;
21+
left:50%;
22+
margin-top:-60px;
23+
margin-left:-65px;
24+
font: 16px 'Open Sans', Helvetica, Arial, sans-serif;
25+
color: #222;
26+
text-transform: uppercase;
27+
text-align: center;
28+
}
29+
30+
#questionButton {
31+
font: 26px 'Montserrat', Helvetica, Arial, sans-serif;
32+
border-radius: 5px;
33+
border: none;
34+
color: #f8f8f8;
35+
background-color: #f16059;
36+
padding: 10px 75px;
37+
display: block;
38+
margin: 0 auto;
39+
}
40+
41+
header {
42+
padding-top: 0.25em;
43+
text-align: center;
44+
}
45+
header span {
46+
font-size: 60px;
47+
color: #f16059;
48+
}
49+
50+
h1, h2, h3, h4, h5, h6 {
51+
font-family: "Montserrat", sans-serif;
52+
}
53+
54+
footer p {
55+
font-family: "Montserrat", sans-serif;
56+
text-align: center;
57+
text-transform: uppercase;
58+
font-size: 12px;
59+
}

0 commit comments

Comments
 (0)