-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmain.js
More file actions
29 lines (25 loc) · 1.04 KB
/
main.js
File metadata and controls
29 lines (25 loc) · 1.04 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
console.log("Main.js working")
const populate = async (value, currency) => {
let myStr = ""
url = "https://api.currencyapi.com/v3/latest?apikey=cur_live_7UStkUqQNBmahSoy8K635tE3Sjr5fK1UVPmVloZ2&base_currency=" + currency
let response = await fetch(url)
let rJson = await response.json()
document.querySelector(".output").style.display = "block"
for (let key of Object.keys(rJson["data"])) {
myStr += ` <tr>
<td>${key}</td>
<td>${rJson["data"][key]["code"]}</td>
<td>${Math.round(rJson["data"][key]["value"] * value)}</td>
</tr>
`
}
const tableBody = document.querySelector("tbody");
tableBody.innerHTML = myStr;
}
const btn = document.querySelector(".btn")
btn.addEventListener("click", (e) => {
e.preventDefault()
const value = parseInt(document.querySelector("input[name='quantity']").value);
const currency = document.querySelector("select[name='currency']").value
populate(value, currency)
})