-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (52 loc) · 1.69 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
63
import { dogProfiles } from "./dog.js";
let profileIndex = -1
const profileElement = document.getElementById("profile-info")
const profileContainer = document.getElementsByClassName("container")[0]
const profileReaction = document.querySelector(".container .reaction img")
profileContainer.addEventListener("click",()=>{
showNextProfile()
})
document.getElementById("btn-heart").addEventListener("click",()=>{
reactionClick("like")
})
document.getElementById("btn-cross").addEventListener("click",()=>{
reactionClick("nope")
})
function reactionClick(reaction){
if (reaction === "like"){
dogProfiles[profileIndex].hasBeenLiked = true
} else{
dogProfiles[profileIndex].hasBeenLiked = false
}
dogProfiles[profileIndex].hasBeenSwiped = true
setReaction()
setTimeout(()=>{showNextProfile()},"3000")
}
function setProfile(){
profileElement.innerHTML = `<h2>${dogProfiles[profileIndex].name}, ${dogProfiles[profileIndex].age}</h2>
<p>${dogProfiles[profileIndex].bio}</p>`
profileContainer.style.backgroundImage = `url("${dogProfiles[profileIndex].avatar}")`
setReaction()
}
function setReaction(){
switch (dogProfiles[profileIndex].getReaction()){
case "nope":
profileReaction.src = "images/badge-nope.png"
profileReaction.style.visibility = "visible"
break;
case "like":
profileReaction.src = "images/badge-like.png"
profileReaction.style.visibility = "visible"
break;
default:
profileReaction.style.visibility = "hidden"
break;
}
}
function showNextProfile(){
// at the end roll back around to dog 1
if (dogProfiles.length-1 === profileIndex) { profileIndex = -1}
profileIndex++
setProfile()
}
showNextProfile()