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: 4 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My Store</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="./main.css">
</head>
<body>
<section id="product-container">
<h1>Shoe Shop</h1>
</section>
<script src="index.js"></script>
</body>
</html>
44 changes: 42 additions & 2 deletions public/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
//stuff
//more stuff
'use strict';

window.onload = function() {
getProducts()
console.log('hi')
}

const getProducts = () => {
fetch('https://my-json-server.typicode.com/jubs16/Products/Products')
.then(response => {
return response.json()
})
.then(data => {
data.forEach(productDiv);
})
}

let productDiv= function(data) {
let section = document.getElementById("product-container");

let div = document.createElement("div");
let img = document.createElement("img");
let p = document.createElement("p");
let button = document.createElement("button");
let name = data.name.toLowerCase();

section.classList.add("flex");
div.classList.add("product");
div.classList.add("flex-column");
p.classList.add("flex-space-between");
p.classList.add("capitalize");
button.classList.add("capitalize");

img.src = data.imgUrl;
p.innerHTML = `<strong>${name}</strong> <strong>$${data.price}</strong>`;
button.innerHTML = "details";

div.appendChild(img);
div.appendChild(p);
div.appendChild(button);
section.appendChild(div);
}
44 changes: 44 additions & 0 deletions public/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
body {
background-color: whitesmoke;
font-family: Helvetica, Arial, sans-serif;
}

.flex {
display: flex;
justify-content: center;
align-items: flex-end;
flex-flow: wrap;
}

.flex-column {
flex-direction: column;
padding: 20px 10px;
}

.flex-space-between {
display: flex;
justify-content: space-between;
}

h1 {
width: 100%;
text-align: center;
}

img {
width: 300px;
max-width: 100%;
height: auto;
}

button {
background-color: blue;
color: whitesmoke;
padding: 8px 10px;
font-size: .8em;
border-radius: 3px;
}

.capitalize {
text-transform: capitalize;
}