-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
23 lines (21 loc) · 901 Bytes
/
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
const request = new XMLHttpRequest(); //create a new request object
request.open('GET','https://hplussport.com/api/products');
request.onload = () =>{
let response = request.response;
let parsedData = JSON.parse(response);
console.log(parsedData); //returs raw data
// use a for loop to return the names of all the products
for(item in parsedData){
let names = parsedData[item].name;//get the names of all the products
let imgUrl = parsedData[item].image //get all the images of the products
// create html elements to store names and images
let list = document.createElement('li');
list.innerHTML = names;
document.body.appendChild(list);
// create an image tag
let img = document.createElement('img');
img.setAttribute('src',imgUrl);
document.body.appendChild(img);
}
}
request.send();