-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (27 loc) · 1.1 KB
/
script.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
$(document).ready(function(){
var magic8Ball = {};
magic8Ball.listOfAnswers = ["Most definitely!", "Ask again later.", "Dream on.", "Possibly…", "Most likely.", "When pigs fly.", "Yes x 1000!"];
magic8Ball.askQuestion = function(question) {
$("#8ball").effect("shake");
$("#answer").fadeIn(4000);
$("#8ball").attr("src", "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/answerside.png");
var randomNumber = Math.random();
var randomNumberForListOfAnswers = randomNumber * this.listOfAnswers.length;
var randomIndex = Math.floor(randomNumberForListOfAnswers);
var answer = this.listOfAnswers[randomIndex];
$("#answer").text(answer);
console.log(question);
console.log(answer);
};
$("#answer").hide();
var onClick = function() {
$("#answer").hide();
$("#8ball").attr("src", "https://s3.amazonaws.com/media.skillcrush.com/skillcrush/wp-content/uploads/2016/09/8side.png");
setTimeout(
function() {
var question = prompt("What is your yes/no question?");
magic8Ball.askQuestion(question);
}, 500);
};
$("#questionButton").click(onClick);
});