-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (52 loc) · 1.43 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const messages = [
"Never",
"Always",
"Maybe",
"Sometimes",
"We shall see",
"Gonna need more info",
"Looks likely",
"Who knows?",
"Heck yeah",
"Hell Na",
"Stop it!",
"Quit Shaking Me!",
"Fa Sho",
"Definitely",
"It is what it is",
];
const getRandomNumber = function() {
return Math.floor(Math.random() * messages.length);
}
/*
Go off and get a random number
then use that random number to pull a
random message from our array of possible responses
*/
const getRandomMessage = function() {
const randomNumber = getRandomNumber();
return messages[randomNumber];
}
/*
Using the getRandomMessage function above to input
a random message into the answer element
*/
const shakeyShakey = function() {
const answerElement = document.getElementById('answer');
answerElement.textContent = getRandomMessage();
const eightElement = document.getElementById('eight');
eightElement.textContent = '';
setTimeout(() => {
const eightElement = document.getElementById('eight');
eightElement.textContent = '8';
const answerElement = document.getElementById('answer');
answerElement.textContent = '';
const inputElement = document.getElementById('question');
inputElement.value = '';
}, 2000);
};
/*
Asking the browser to call shakeyShakey whenever the button is clicked
*/
const buttonElement = document.getElementById('button');
buttonElement.addEventListener('click', shakeyShakey);