Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let request = new XMLHttpRequest();
  2. request.open(
  3.   "GET",
  4.   "https://www.unisport.dk/api/products/batch/?list=179249,179838,174351,180011,180020,178429"
  5. );
  6. request.onload = function() {
  7.   let data = JSON.parse(request.responseText).products;
  8.   console.log(data);
  9.   renderHTML(data);
  10.   currencyFormat(data);
  11. };
  12. request.send();
  13.  
  14. function renderHTML(data) {
  15.   let slider = document.getElementById("slider");
  16.   for (let product of data) {
  17.     //you dont need to pass the whole data since you use only price, pass only price
  18.     let converted_price = currencyFormat(product.price);
  19.     slider.innerHTML +=
  20.       '<div class="product">' +
  21.       '<img class="item-image" src="' +
  22.       product.image +
  23.       '" alt="image" width="100" height="100">' +
  24.       '<div class="product-description">' +
  25.       //notice here
  26.       converted_price +
  27.       "</div>" +
  28.       product.name +
  29.       '<div class="size">' +
  30.       '<select name="size"><option value="">Choose Size</option><option value="'+product.sizes+'"</option></select></div>'+
  31.       "</div>" ;
  32.   }
  33. }
  34. function currencyFormat(price) {
  35.       let formatter = new Intl.NumberFormat("da-DK", {
  36.         style: "currency",
  37.         currency: "DKK",
  38.         minimumFractionDigits: 2
  39.       });
  40.       let formatted = formatter.format(price);
  41.       // console.log(formatted);
  42.       return formatted;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement