Skip to content

Commit

Permalink
Complete Assignment2
Browse files Browse the repository at this point in the history
  • Loading branch information
yinxoxo committed Jul 10, 2024
1 parent 99e7f3f commit b368694
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Week4/Assignment2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function ajax(apiUrl) {
return fetch(apiUrl)
.then((response) => {
return response.json();
})
.catch((error) => {
console.error(error);
});
}

function render(data) {
document.body.innerHTML = "";

// 建立ul,放到body
const ul = document.createElement("ul");
document.body.appendChild(ul);

//product資訊放入li
data.forEach((product) => {
const li = document.createElement("li");
li.textContent = ` Name: ${product.name}, Price: ${product.price}, Description: ${product.description}`;
ul.appendChild(li);
});
}

const apiUrl =
"https://remote-assignment.s3.ap-northeast-1.amazonaws.com/products";

ajax(apiUrl).then((data) => {
render(data);
});

0 comments on commit b368694

Please sign in to comment.