-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
83 lines (69 loc) · 2.21 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* shuffle()
* Shuffle the contents of an array
* depending the datatype of the source
* Makes a copy. Does NOT shuffle the original.
* Based on Steve Griffith's array shuffle prototype
* @Parameters: Array or string
* @Return: Scrambled Array or string, based on the provided parameter
*/
function shuffle (src) {
const copy = [...src]
const length = copy.length
for (let i = 0; i < length; i++) {
const x = copy[i]
const y = Math.floor(Math.random() * length)
const z = copy[y]
copy[i] = z
copy[y] = x
}
if (typeof src === 'string') {
return copy.join('')
}
return copy
}
// ANSWERS
const answers = ['MAYBE', 'NEVER', 'POSSIBLY', 'DEFINITELY', 'SURE', 'NOPE', 'I GUESS?', 'TRY AGAIN', 'YES']
const shuffledAnswers = shuffle(answers)
// VUE APP
const app = new Vue ({
el: '#app',
data: {
gameStatus: false,
answers: shuffledAnswers,
answer: '',
question: ''
},
methods: {
shakeAnimation: function () {
const eightBall = document.querySelector('.eightBall')
eightBall.classList.add('animate__animated', 'animate__wobble', 'animate__fast')
eightBall.addEventListener('animationend', () => {
eightBall.className = 'eightBall'
})
},
fadeInAnimation: function () {
const answerBit = document.querySelector('.answerBit')
answerBit.classList.add('animate__animated', 'animate__fadeIn', 'animate__fast')
answerBit.addEventListener('animationend', () => {
answerBit.className = 'answerBit'
})
},
clearInput: function () {
this.question = ''
event.target = ''
},
onEnter: function () {
if (this.question.length > 0) {
this.gameStatus = true
}
this.clearInput()
this.shakeAnimation()
this.fadeInAnimation()
var tempArray = shuffle(this.answers)
this.answer = tempArray[0]
return this.answer
}
}
})
console.log(shuffledAnswers)