39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
function renderData(data) {
|
|
const container = document.querySelector(".data-container");
|
|
if (container) {
|
|
// Clear previous content (if any)
|
|
container.innerHTML = "";
|
|
|
|
// Create and append elements for each data field
|
|
const cryptoElement = document.createElement("p");
|
|
cryptoElement.textContent = `Crypto: ${data.crypto}`;
|
|
container.appendChild(cryptoElement);
|
|
|
|
const currencyElement = document.createElement("p");
|
|
currencyElement.textContent = `Currency: ${data.currency}`;
|
|
container.appendChild(currencyElement);
|
|
|
|
const priceElement = document.createElement("p");
|
|
priceElement.textContent = `Price: ${data.price}`;
|
|
container.appendChild(priceElement);
|
|
} else {
|
|
console.error("Data container not found in the DOM.");
|
|
}
|
|
}
|
|
|
|
function get (url) {
|
|
|
|
return fetch (url)
|
|
.then ( res => {
|
|
return res.json();
|
|
})
|
|
.then (data => {
|
|
renderData (data);
|
|
console.log(data);
|
|
})
|
|
|
|
}
|
|
|
|
|
|
get ("./data/data.json");
|