-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (54 loc) · 1.59 KB
/
index.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
import dogs from './data.js'
import Dog from './Dog.js'
import { disableButtons, enableButtons } from './utils.js'
function getNewDog(){
const newDogData = dogs.shift()
return newDogData ? new Dog(newDogData) : {}
}
let dog = getNewDog()
function render(){
document.getElementById('card').innerHTML = dog.getDogHtml()
}
render()
document.querySelector('.icon-heart-wrapper').addEventListener('click', like)
document.querySelector('.icon-cross-wrapper').addEventListener('click', reject)
function like(){
document.getElementById('accept-state').setAttribute('style', 'display: block')
disableButtons()
setTimeout(()=>{
if(dogs.length > 0){
dog = getNewDog()
document.getElementById('accept-state').setAttribute('style', 'display: none')
render()
dog.hasBeenSwiped = true
enableButtons()
}
else {
endGame()
}
},1500)
}
function reject(){
document.getElementById('reject-state').setAttribute('style', 'display: block')
disableButtons()
setTimeout(()=>{
if (dogs.length > 0){
dog = getNewDog()
document.getElementById('reject-state').setAttribute('style', 'display: none')
render()
dog.hasBeenSwiped = true
enableButtons()
}
else {
endGame()
}
},1500)
}
function endGame() {
document.body.innerHTML = `
<div class='end-info'>
<h1 class='end-message'>We've ran out of cuteness!</h1>
<p class='end-emoji'>🤭</p>
</div>
`
}