-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (38 loc) · 1.17 KB
/
Copy pathscript.js
File metadata and controls
49 lines (38 loc) · 1.17 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
//create a list of strings, to hold 8 ball responses
var list = ["Yes",
"No",
"It's decidedly so",
"Outlook not so good",
"Concentrate and try again",
"Try again",
"Don't count on it.",
"My reply is no",
"Signs point to yes",
"Reply hazy, try again"];
var imageState = "front";
//this function outputs a random number
function randomNum(){
return Math.floor(Math.random() * 10);
}
//this function responds with a fortune
//when click the magic 8 ball image
function shakeMagic8Ball(){
//if the picture is of the front side...
if(imageState == "front"){
//grab image by id
document.getElementById("magic8ball").src="magic8ballback.jpg";
//grab the results
document.getElementById("results").innerHTML=list[randomNum()];
imageState = "back";
}
//else, it's picture of the back side...
else{
//go back to the front picture
document.getElementById("magic8ball").src="magic8ballfront.jpg";
//change results paragraph to say something to propmt the user
//to shake the 8 ball again
document.getElementById("results").innerHTML="click the magic 8 ball to tell your fortune.";
imageState = "front";
}
//alert(randomNum());
}