Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

</head>
<body>
<h2>Products Available:</h2>
<button id="clickButton">Click for products</button>
<ul id="productList">

</ul>
<script src="index.js"></script>
</body>
</html>
33 changes: 32 additions & 1 deletion public/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
//stuff
//more stuff
//more stuff
'use strict'
let arrayOfBreweries
let arrayOfPosts
console.log("working!")

const getProducts = () =>{
fetch('https://my-json-server.typicode.com/jubs16/Products/Products')
.then(res => res.json())
.then(posts => arrayOfPosts = posts)
console.log(arrayOfPosts)
}
const button = document.getElementById("clickButton")
clickButton.addEventListener('click', function(){
console.log("Clicked")
getProducts()
console.log(arrayOfPosts)
for(let i =0; i < arrayOfPosts.length; i++){
console.log(arrayOfPosts[i].name)
let li = document.createElement("li")
let img = document.createElement("img")
img.src = arrayOfPosts[i].imgUrl
img.height = '200'
console.log(arrayOfPosts[i].imgURL)
li.innerHTML = `${arrayOfPosts[i].name} costs $${arrayOfPosts[i].price} and looks like : `
let ul = document.getElementById("productList")
li.appendChild(img)
ul.appendChild(li)
}
})