-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (49 loc) · 2.03 KB
/
script.js
File metadata and controls
60 lines (49 loc) · 2.03 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
50
51
52
53
54
55
56
57
58
59
60
document.addEventListener("DOMContentLoaded", () => {
fetchFish(null)
document.getElementById("fishSearch").addEventListener('click', (e) => {
document.getElementById("table-body").innerHTML = ""
fetchFish(document.getElementById("fishName").value)
})
})
const fetchFish = (filter) => (
fetch ("http://acnhapi.com/v1/fish/")
.then (Response => Response.json())
.then (fishData => {
Object.keys(fishData).forEach( key => {
// console.log(key)
let name = fishData[key].name["name-USen"]
if (filter==null) {
renderFish(fishData[key])
} else if (name.includes(filter)) {
renderFish(fishData[key])
}
})
})
)
const renderFish = (fish) => {
let tableBody = document.getElementById('table-body')
let tableRow = document.createElement('tr')
tableRow.className = 'fish-name'
let tableDataName = document.createElement('td')
tableDataName.textContent = fish.name["name-USen"]
let tableDataTime = document.createElement('td')
tableDataTime.textContent = fish.availability.time
let tableDataPrice = document.createElement('td')
tableDataPrice.textContent = fish.price
let tableDataShadow = document.createElement('td')
tableDataShadow.textContent = fish.shadow
let tableDataCatch = document.createElement('td')
let catchButton = document.createElement('button')
catchButton.textContent = 'Catch Fish'
let catchFish = fish['catch-phrase']
addCatchListener(catchButton, catchFish, tableDataCatch)
tableRow.append(tableDataName, tableDataTime, tableDataPrice, tableDataShadow, tableDataCatch, catchButton)
tableBody.append(tableRow)
}
const addCatchListener = (catchButton, catchFish, tableDataCatch) => {
catchButton.addEventListener('click', (e) => {
tableDataCatch.textContent = catchFish
})
}
//point before changes!!!!!
//comment above was just so i could have a safe "undo until this disappears" point just in case my code didnt work