var is a keybord that work without declare var ketboard.
Print second element Kia only.
Run above Array using for loop.
Object in javascript , lot of things we know about Javascript are basically Object.
We have few pre defined object as well. We have the Math Object/ Date Object / Regular Express are also considered as an object in javascript.
string is a datatype and we also use string as an Object like below.
ii. Constractor Function.
It is not a good practice to edit Object Dot prototype.
This is the basic syntax of class, and how we are going create class in JavaScript
Here we wrongly call unknown function name and this type of error are Reference error.
Customise error for watch to the user.
43. Debugging Using chrome Developer
44. Iterators and Generators in JavaScript
iterator is an object that return an Object with two propertise.
var arr = ["BMW","Audi","Mercedes","Jugar"];
// console.log(arr);
// console.log(arr.length);
for(let i = 0; i < arr.length; i++){
console.log(arr[i]);
}
// use above for loop using "for of" loop. same output.
for(let i of arr)
{
console.log(i);
}
output:
This is iterators (Keep in mind interviewer ask about it)
function cars(values)
{
let index = 0;
return{
next: function(){ // next is a function here which will be call to print the current element value
if(index < values.length)
return{
value: values[index++],
done: false
}
else{
return{
done: true
}
}
}
}
};
var arr = ["BMW","Audi","Mercedes","Jugar"];
var newCars = cars(arr);
console.log(newCars.next())
output:
Object { value: "BMW", done: false }
function cars(values)
{
let index = 0;
return{
next: function(){ // next is a function here which will be call to print the current element value
if(index < values.length)
return{
value: values[index++],
done: false
}
else{
return{
done: true
}
}
}
}
};
var arr = ["BMW","Audi","Mercedes","Jugar"];
var newCars = cars(arr);
console.log(newCars.next())
console.log(newCars.next())
console.log(newCars.next())
console.log(newCars.next())
console.log(newCars.next())
output:
Object { value: "BMW", done: false }
Object { value: "Audi", done: false }
Object { value: "Mercedes", done: false }
Object { value: "Jugar", done: false }
Object { done: true }
function cars(values)
{
let index = 0;
return{
next: function(){ // next is a function here which will be call to print the current element value
if(index < values.length)
return{
value: values[index++],
done: false
}
else{
return{
done: true
}
}
}
}
};
var arr = ["BMW","Audi","Mercedes","Jugar"];
var newCars = cars(arr);
console.log(newCars.next().value)
output: BMW
function cars(values)
{
let index = 0;
return{
next: function(){ // next is a function here which will be call to print the current element value
if(index < values.length)
return{
value: values[index++],
done: false
}
else{
return{
done: true
}
}
}
}
};
var arr = ["BMW","Audi","Mercedes","Jugar"];
var newCars = cars(arr);
console.log(newCars.next().value)
console.log(newCars.next().value)
console.log(newCars.next().value)
console.log(newCars.next().value)
console.log(newCars.next().value)
output:
BMW
Audi
Mercedes
Jugar
undefined
Generator
Generator functions allow us to define an iterative algorithims by writing single non continuous function.
generator create with asteric (*) after function.
asteric tell us this, this not a general function, this is generator function.
function* generate()
{
let i = 0;
yield "BMW";
yield "Audi";
yield "Mercedes";
yield "Jugar";
}
let gen = generate()
console.log(gen.next())
output:
Object { value: "BMW", done: false }
function* generate()
{
let i = 0;
yield "BMW";
yield "Audi";
yield "Mercedes";
yield "Jugar";
}
let gen = generate()
console.log(gen.next())
console.log(gen.next())
console.log(gen.next())
console.log(gen.next())
console.log(gen.next())
output:
Object { value: "BMW", done: false
Object { value: "Audi", done: false
Object { value: "Mercedes", done: false
Object { value: "Jugar", done: false }
Object { value: undefined, done: true }
function* generate()
{
let i = 0;
var ar = ["BMW", "Audi", "Mercedes","Jugar"]
while(i<ar.length)
{
yield ar[i]
i++;
}
}
let gen = generate()
console.log(gen.next())
output:
Object { value: "BMW", done: false }
function* generate()
{
let i = 0;
var ar = ["BMW", "Audi", "Mercedes","Jugar"]
while(i<ar.length)
{
yield ar[i]
i++;
}
}
let gen = generate()
console.log(gen.next())
console.log(gen.next())
console.log(gen.next())
console.log(gen.next())
console.log(gen.next())
output:
Object { value: "BMW", done: false }
Object { value: "Audi", done: false }
Object { value: "Mercedes", done: false }
Object { value: "Jugar", done: false }
Object { value: undefined, done: true }
function* generate()
{
let i = 0;
var ar = ["BMW", "Audi", "Mercedes","Jugar"]
while(i<ar.length)
{
yield ar[i]
i++;
}
}
let gen = generate()
console.log(gen.next().value)
console.log(gen.next().value)
console.log(gen.next().value)
console.log(gen.next().value)
console.log(gen.next().value)
output:
BMW
Audi
Mercedes
Jugar
undefined
45. Maps
Maps and Object are same but little different.
var myCar = new Object()
{
myCar.manufacturer ="Ford";
myCar.name = "Raptor";
myCar.color = "Black";
}
// console.log(myCar);
// console.log(myCar.color);
myCar.make = 2012;
console.log(myCar);
// This is an empty Object
var myName = new Object()
{
}
// This is an empty Map
var myNmae = new Map()
{
}
// This is Map
var myNmae = new Map()
{
myNmae.set(1,"BMW")
myNmae.set(2,"Audi")
myNmae.set(3,"Mercedes")
}
console.log(myNmae);
var myNmae = new Map()
{
myNmae.set(1,"BMW")
myNmae.set(2,"Audi")
myNmae.set(3,"Mercedes")
}
// console.log(myNmae);
// This is Map with get method
console.log(myNmae.get(3))
// This is Map with set method
var myNmae = new Map()
{
myNmae.set(1,"BMW")
myNmae.set(2,"Audi")
myNmae.set(3,"Mercedes")
}
// console.log(myNmae);
// This is Map with get method
// console.log(myNmae.get(3))
// map size function
console.log(myNmae.size);
var myNmae = new Map()
{
myNmae.set("My car name is", "Jugar");
myNmae.set({}, "Honda");
myNmae.set(function (){}, "Mercedes");
}
console.log(myNmae)
var myNmae = new Map()
var obj = {};
let func = function (){}
{
myNmae.set("My car name is", "Jugar");
myNmae.set(obj, "Honda");
myNmae.set(func, "Mercedes");
}
console.log(myNmae.get(func))
var myNmae = new Map()
var obj = {};
let func = function (){}
{
myNmae.set("My car name is", "Jugar");
myNmae.set(obj, "Honda");
myNmae.set(func, "Mercedes");
}
console.log(myNmae.get(obj))
var myarr = [[1, "BMW"], [2, "Audi"],[3,"Honda"]]
var myCar = new Map(myarr)
console.log(myCar.get(2));
using for Loop
var myarr = [[1, "BMW"], [2, "Audi"],[3,"Honda"]]
var myCar = new Map(myarr)
console.log(myCar.get(2));
for(let [key,value] of myCar)
{
console.log(key + " " + value);
}
var myarr = [[1, "BMW"], [2, "Audi"],[3,"Honda"]]
var myCar = new Map(myarr)
console.log(myCar.get(2));
for(let [key,value] of myCar)
{
console.log(key);
}
we can clone using map
var myarr = [[1, "BMW"], [2, "Audi"],[3,"Honda"]]
var myCar = new Map(myarr)
var yourCar = new Map(myCar)
console.log(yourCar)
46. Set
set in javacript is an Object. Set similar to map in javascript. It ,it meams they are
also an Object but they perform various activity other than Map. Syntax is also same and even propertise are also same.
Set strore Unique Value.
This is the syntax of set in JavaScript
var myset = new Set()
console.log(myset);
var myset = new Set()
myset.add(1)
myset.add(2)
myset.add(3)
myset.add(4)
myset.add(3) // SET NOT ALLOWED 3 AGAIN
console.log(myset);
output:
Set(4) [ 1, 2, 3, 4 ]
let arr = [1,2,3,4,3,45,3,5,6,2,3,2]
let myset2 = new Set(arr)
console.log(myset2);
output: Set(7) [ 1, 2, 3, 4, 45, 5, 6 ]
let arr = [1,2,3,4,3,45,3,5,6,2,3,2]
let myset2 = new Set(arr)
console.log(myset2);
let myArr = Array.from(myset2)
console.log(myArr);
outpt:
Set(7) [ 1, 2, 3, 4, 45, 5, 6 ]
Array(7) [ 1, 2, 3, 4, 45, 5, 6 ]
let arr = [1,2,3,4,3,45,3,5,6,2,3,2]
let myset2 = new Set(arr)
console.log(myset2);
let myArr = Array.from(myset2)
console.log(myArr);
for(let item of myset2)
console.log(item)
Output:
Set(7) [ 1, 2, 3, 4, 45, 5, 6 ]
Array(7) [ 1, 2, 3, 4, 45, 5, 6 ]
1
2
3
4
45
5
6
let arr = [1,2,3,4,3,45,3,5,6,2,3,2]
let myset2 = new Set(arr)
// delete a set
myset2.delete(45)
console.log(myset2);
output:
Set(6) [ 1, 2, 3, 4, 5, 6 ]
let arr = [1,2,3,4,3,45,3,5,6,2,3,2]
let myset2 = new Set(arr)
myset2.clear();
console.log(myset2);
output:
Set []
47. Flopply Bird Games
Html File
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flappy Birds</title>
<link rel="stylesheet" href="flappyzBird.css">
</head>
<body>
<div id="game">
<div id="block"></div>
<div id="hole"></div>
<div id="bird"><img src="bird2.png" alt="Bird"> </div>
</div>
<div id="result">
<h1>Game Over</h1>
<p id="text"></p>
<button id="btn" onclick="location.reload()">Restart</button>
</div>
<script src="flappyBird.js"></script>
</body>
</html>
CSS file
*{
margin: 0;
padding: 0;
}
body
{
background-color: cadetblue;
background-image: -webkit-linear-gradient(rgb(175,75,75), rgb(31,31,31),rgb(59,153,148));
min-height: 800px;
}
#game
{
height: 500px;
width: 400px;
border: 1px solid black;
background: url(bg1.jpg);
background-size: cover;
margin: 1rem auto;
overflow: hidden;
}
#block
{
width: 50px;
height: 500px;
background-color: rgb(15, 17, 15);
position: relative;
left: 400px;
animation: block 2s linear infinite;
}
@keyframes block{
0%{
left: 400px;
}
100%{
left: -50px;
}
}
#hole{
height: 150px;
width: 50px;
background-color: rgb(250, 155, 2);
position: relative;
left: 400px;
top: -500px;
animation: block 2s linear infinite;
}
#bird
{
position: fixed;
top: 100px;
height: 50px;
width: 50px;
}
#bird img
{
height: 50px;
width: 50px;
}
#result{
height: 200px;
width: 500px;
background-color: brown;
margin: 5rem auto;
border: 2px solid white;
border-radius: 20px;
display: none;
text-align: center;
}
#btn{
padding: 0.5 rem 1rem;
border: none;
border-radius: 11px;
background-color: rgb(63, 53, 53);
color: white;
font-size: 1.5 rem;
text-transform: uppercase;
margin-top: 1rem;
cursor: pointer;
}
#text{
margin: 1rem;
font-size: 2rem;
color: seashell;
}
JS File
var hole = document.getElementById("hole");
var game = document.getElementById("game");
var result = document.getElementById("result");
var text = document.getElementById("text");
var score = 0;
var jumping = 0;
hole.addEventListener("animationiteration", RanHole)
function RanHole(){
var random = -((Math.random()*350)+150)
hole.style.top = random+"px";
score++
}
var fall = setInterval(function(){
var birdTop = parseInt(window.getComputedStyle(bird).getPropertyValue("top"));
if(jumping ==0)
{
bird.style.top = (birdTop+2)+"px";
}
var blockLeft =parseInt(window.getComputedStyle(block).getPropertyValue("left"))
var holeTop = parseInt(window.getComputedStyle(hole).getPropertyValue("top"));
var hTop = (500+holeTop)
if((birdTop >450) || ((blockLeft<50)&& ((birdTop < hTop ||(birdTop > hTop + 100)))))
{
result.style.display = "block";
text.innerText = `your final score is : ${score}`;
game.style.display = "none";
score = 0;
}
},10)
window.addEventListener("keydown",hop)
function hop()
{
jumping = 1;
var birdTop = parseInt(window.getComputedStyle(bird).getPropertyValue("top"))
if(birdTop > 6)
{
bird.style.top = (birdTop - 60) + "px";
}
setTimeout(function(){
jumping = 0
},100)
}
48. Website Book Selling Project By JS
JS File
const cart = document.querySelector("nav .cart")
var cartSidebar = document.querySelector(".cart-Sidebar")
const closeCart = document.querySelector(".close-cart")
const burger = document.querySelector(".burger")
const menuSidebar = document.querySelector(".menu-sidebar")
const closeMenu = document.querySelector(".close-menu")
const cartItemsTotal = document.querySelector("noi")
const cartPriceTotal = document.querySelector(".total-amount")
const cartUi = document.querySelector(".cart-sidebar .cart")
const totalDiv = document.querySelector(".total-sum")
const clearBtn = document.querySelector(".clear-cart-btn")
const cartContent = document.querySelector(".cart-content")
let Cart = [];
let buttonsDOM = [];
cart.addEventListener("click", function () {
cartSidebar.style.transform = "translate(0%)"
const bodyOverlay = document.createElement("div")
bodyOverlay.classList.add("overlay");
setTimeout(function () {
document.querySelector("body").append(bodyOverlay)
}, 300)
})
closeCart.addEventListener("click", function () {
cartSidebar.style.transform = "translate(100%)"
const bodyOverlay = document.querySelector(".overlay")
document.querySelector("body").removeChild(bodyOverlay)
})
burger.addEventListener("click", function () {
menuSidebar.style.transform = "translate(0%)"
})
closeMenu.addEventListener("click", function () {
menuSidebar.style.transform = "translate(-100%)"
})
class Product {
async getProduct() {
const response = await fetch("product.json");
const data = await response.json();
let products = data.items;
products = products.map(item => {
const { title, price } = item.fields;
const { id } = item.sys;
const image = item.fields.image.fields.file.url;
return { title, price, id, image };
})
return products;
}
}
class UI {
displayProducts(products) {
let result = "";
products.forEach(product => {
const productDiv = document.createElement("div")
productDiv.innerHTML = `<div class = "product-card">
<img src="${product.image}" alt="product">
<span class= "add-to-cart" data-id="${product.id}">
<i class = "fa fa-cart--plus fa-1x"
style = "margin-right:0.1em; font-size:1em;"></i>
add to cart
</span>
<div class= "product-name">${product.title} </div>
<div class= "product-pricing">${product.price}
</div>`
const p = document.querySelector(".product")
p.append(productDiv)
})
}
}
getButtons()
{
const btns = document.querySelectorAll(".add-to-cart")
Array.from(btns)
buttonsDOM = btns;
btns.forEach((btn) => {
let id = btn.dataset.id
let inCart = Cart.find((item) => item.id === id);
if (inCart) {
btn.innerHTML = "In Cart"
btn.dissabled = true
}
btn.addEventListener("click", (e) => {
e.currentTarget.innerHTML = "In Cart"
e.currentTarget.style.color = "white"
e.currentTarget.style.pointerEvents = "none"
let cartItem = { ...Storage.getStorageProducts(id), 'amount': 1 }
Cart.push(cartItem)
Storage.saveCart(Cart)
this.setCartValues(Cart)
this.addCartItem(cartItem)
})
})
}
setCartValues(cart)
{
let tempTotal = 0;
let itemTotal = 0;
Cart.map((item) => {
tempTotal += (item.price * item.amount);
itemTotal += item.amount;
parseFloat(tempTotal.toFixed(2))
})
cartItemsTotal.innerHTML = itemsTotal
cartPriceTotal.innerHTML = parseFloat(tempTotal.toFixed(2))
}
addCartItem(cartItem)
{
let cartItemUi = document.createElement("div")
cartItemUi.innerHTML = `<div class= "cart-product">
<div class = "product-image">
<img src = "${cartItem.image} alt="product">
</div>
<div class = "cart-product-content">
<div class = "cart-product-name"><h3>${cartItem.title}</h3></div>
<div
class= "cart-product-price"><h3>${cartitem.price}</h3></div>
<div class= "cart-product-remove data-id="${cartItem.id}"
href="#" style="color:red;>remove</a></div>
</div>
<div class= "plus-minus">
<i class = "fa fa-angle-left add-amount"
data-id="${cartItem.id}"></i>
<span class="no-of-items">${cartItem.amount}</span>
data-id="${cartItem.id}"</i>
</div>
</div>`
cartContent.append(cartItemUi)
}
setupApp()
{
Cart = Storage.getCart()
this.setCartValues(Cart)
Cart.map((item) => {
this.addCartItem(item)
})
}
cartLogic()
{
clearBtn.addEventListener("click", () => {
this.closeCart()
})
cartContent.addEventListener.apply("click", (event) => {
if (event.target.classList.contains("cart-product-remove")) {
let id = event.target.dataset.id
this.remobeItem(id)
let div = event.target.parentElement.parentElement.parentElement.parentElement
div.removeChild(event.target.parentElement.parentElement.parentElement.parentElement)
}
else if (event.target.classList.contains("add-amount")) {
let id = event.target.dataset.id
let item = Cart.find((item) => item.id === id)
item.amount++
Storage.saveCart(Cart)
this.setCartValues(Cart)
event.target.nextElemetSibling.innerHTML = item.amount
}
else if (event.target.classList.contains("reduce-amount")) {
let id = event.target.dataset.id
let item = Cart.find((item) => item.id === id)
if (item.amount > 1) {
item.amount--
Storage.saveCart(Cart)
this.setCartValues(Cart)
event.target.previousElementSibling.innerHTML = item.amount
}
else {
this.remobeItem(id)
let div = event.target.parentElement.parentElement.parentElement.parentElement
div.removeChild(event.target.parentElement.parentElement.parentElement.parentElement)
}
}
})
}
addAmount()
{
const addBtn = document.querySelectorAll(".add-amount")
addBtn.forEach((btn) => {
btn.addEventListener("click", (event) => {
let id = (event.currentTarget.dataset.id)
Cart.map((item) => {
if (item.id === id) {
item.amount++
Storage.saveCart(Cart)
this.setCartValues(Cart)
const amountUi = event.currentTarget.parentElement.children[1]
amountUi.innerHTML = item.amount
}
})
})
})
}
reduceAmount()
{
const reduceBtn = document.querySelectorAll(".reduce-amount")
reduceBtn.forEach((btn) => {
btn.addEventListener("click", (event) => {
let id = (event.currentTarget.dataset.id)
Cart.map((item) => {
if (item.id === id) {
item.amount--
if (item.amount > 0) {
Storage.saveCart(Cart)
this.setCartValues(Cart)
const amountUi = event.currentTarget.parentElement.children[1]
amountUi.innerHTML = item.amount
} else {
event.currentTarget.parentElement.parentElement.parentElement.removeChild(event.currentTarget.parentElement.parentElement)
this.removeItem(id)
}
}
})
})
})
}
closeCart()
{
let cartItem = Cart.map(item => item.id)
cartItem.forEach((id) => this.removeItem(id))
const cartProduct = document.querySelectorAll(".cart-product")
cartProduct.forEach((item) => {
if (item) {
item.parentElement.removeChild(item)
}
})
}
removeItem(id)
{
Cart = Cart.filter((item) => item.id !== id)
this.setCartValues(Cart)
Storage.saveCart(Cart)
let button = this.getSingleButton(id)
button.style.pointerEvents = "unset"
button.innerHTML = `<i class= "fa fa-cart-plus"></i> Add To Cart`
}
getSingleButton(id)
{
let btn
buttonsDOM.forEach((button) => {
if (button.dataset.id === id) {
btn = button
}
return btn
})
}
class Storage{
static saveProducts(products){
localStorage.setItem("products",JSON.stringify(products))
}
static getStorageProducts(id){
let products= JSON.parse(localStorage.getItem('products'))
return products.find((item)=>item.id===id)
}
static saveCart(Cart){
localStorage.setItem('Cart',JSON.stringify(Cart))
}
static getCart(){
return loocalStorage.getItem('Cart')? JSON.parse(localStorage.getItem("Cart")):[]
}
}
document.addEventListener("DOMContentLoaded",()=>{
const products = new Products();
const ui = new UI();
ui.setupApp()
products.getProduct().then(products=>{
ui.displayProducts(products)
Storage.saveProducts(products)
}).then(()=>{
ui.getButtons();
ui.cartLogic();
})
})
CSS File
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-size: 20px;
}
html{
scroll-behavior: smooth;
}
a{
text-decoration: none;
}
ul{
list-style: none;
}
.navbar{
display: flex;
justify-content: space-between;
align-items: center;
height: 10vh;
background-color: white;
}
.logo{
padding-left: 2em;
}
.logo-text{
font-size: 2em;
}
.menubar{
width: 45%;
margin-left: 8.5em;
}
.list{
display: flex;
justify-content: space-between;
}
.list-items a{
color: black;
font-family: sans-serif;
font-size: 0.9em;
transition: 0.4s;
}
.list-items a:hover{
color: black;
}
.cart{
padding-right: 2em;
position: relative;
}
.cart .number-of-items{
display: flex;
cursor: pointer;
justify-content: center;
align-items: center;
color: white;
position: absolute;
left: 18px;
top: -7px;
background: #f09d51;
height: 20px;
width: 20px;
border-radius: 7px;
}
.number-of-items .noi{
font-size: 0.7em;
}
.fa-shopping-cart{
font-size: 1.5em;
cursor: pointer;
}
.burger{
height: 28px;
width: 32px;
display: none;
}
.layer1, .layer2,.layer3{
background: black;
height: 4px;
margin-top: 4px;
width: 100%;
border-radius: 10px;
}
.section1{
height: calc(100vh - 10vh);
width: 100%;
background: url("back3.jpg") center center/cover;
top: 0;
left: 0;
z-index: -1;
}
.section1 .banner{
height: 170px;
width: 600px;
background: rgba(255,255,255,0.7);
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
justify-content: space-around;
flex-direction: column;
text-align: center;
align-items: center;
font-family: sans-serif;
z-index: 8;
}
.banner h1{
font-size: 2em;
}
.banner a{
display: flex;
justify-content: center;
padding: 1em 2.5em;
font-size: 0.8em;
color: white;
background: #f09d51;
transition: all 0.3s;
}
.banner a:hover{
background: hsl(120, 85%, 43%);
}
.section2.title{
text-align: center;
}
.section2 .title h1{
font-size: 1.8em;
margin: 1.3em;
}
.product{
margin: 0.5em auto;
max-width: 1300px;
display: grid;
grid-column-gap: 2em;
grid-row-gap: 2em;
grid-template-columns: repeat(auto-fit, minmax(350px,1fr));
}
.product-card{
text-align: center;
position: relative;
max-width: 350px;
overflow: hidden;
}
.product-card img{
height: 300px;
width: 300px;
transition: 0.3s linear;
}
.product-name,.product-pricing{
margin: 0.3em;
}
.product-pricing{
color: #f09d51;
}
.add-to-cart{
align-items: center;
justify-content: center;
color: white;
padding: 0.2em 1em;
height: 30px;
background: #f09d51;
right: 0;
transform: translateX(100%);
bottom: 80px;
transition: 03s linear;
cursor: pointer;
}
.product-card:hover .add-to-cart{
transform: translate(0%);
}
.product-card:hover img{
opacity: 0.7;
}
.add-to-cart:hover{
color: black;
}
/* menubar */
.menu-sidebar{
display: none;
}
.cart-sidebar{
background: #ececec;
position: fixed;
right: 0;
top: 0;
width: 450px;
height: 100vh;
z-index: 10;
transition: all 0.3s linear;
transform: translateX(100%);
overflow: scroll;
}
.cart-sidebar .cart{
padding: 0;
}
.cart .close-cart{
font-size: 1.3em;
padding: 1em;
cursor: pointer;
}
.fa-times{
margin-top: 0.5em;
}
cart h2{
text-align: center;
width: 100%;
margin-bottom: 1em;
font-size: 1.1em;
font-family: Verdana;
}
.cart-product .product-image img{
width: 130px;
height: 90px;
}
.cart-product-contnent{
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
margin-left: 1em;
height: 80px;
}
.plus-minus{
display: flex;
transform: rotate(90deg);
color: #f09d51;
font-size: 1.5em;
cursor: pointer;
}
.total-sum{
text-align: center;
margin: 1em 0 0.5em 0;
}
.clear-cart{
text-align: center;
}
.clear-cart .btn{
background-color: #d4761e;
color: white;
border: 1px solid white;
padding: 0.5em 1.7em;
cursor: pointer;
transition: 0.3s linear;
}
.clear-cart .btn:hover{
border: 1px solid #d4761e;
background: transparent;
color: black;
}
.overlay{
height: 100vh;
position: fixed;
top: 0;
left: 0;
z-index: 9;
width: 100%;
background-color: #f3851f;
opacity: 0.3;
transition: all 0.3s linear;
}
.none{
display: none;
}
@media screen and (max-width:768px){
.logo{
padding-left: 0;
}
.cart{
padding-right: 2em;
}
.menubar{
display: none;
}
.burger{
margin-left: 2em;
display: block;
}
.section1 .banner h1{
font-size: 1.5em;
}
.banner a{
font-size: 0.6em;
padding: 1em 2em;
}
.section2 .title h1{
font-size: 1.5em;
}
.menu-sidebar{
display: block;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100vh;
z-index: 11;
background: #ececec;
overflow: hidden;
transform: translate(-100%);
transition: 0.3s linear;
}
.menu-menubar{
display: flex;
height: 80%;
justify-content: center;
}
.menu-list{
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
}
.menu-sidebar .close-menu{
position: absolute;
right: 30px;
font-size: 1.4em;
}
.menu-list-items a{
color: #f09d51;
}
.menu-list-items a:hover{
color: #f57b09;
}
}
@media screen and (max-width:480px){
*{
font-size: 16px;
}
.section1 .banner{
width: 280px;
height: 100px;
}
.section1 .banner h1{
font-size: 1.2em;
}
.burger{
margin-left: 1em;
display: block;
width: 30px;
}
.cart-sidebar{
width: 100%;
}
.product{
margin: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
}
JSON File
{
"items":
[
{
"sys":{"id": "1"},
"fields":{
"title": "Python proramming Master course.",
"price": 1234.99,
"image":{"fields":{"file":{"url":"back1.jpg"}}}
}
},
{
"sys":{"id": "2"},
"fields":{
"title": "Java proramming Master course.",
"price": 1234.99,
"image":{"fields":{"file":{"url":"back1.jpg"}}}
}
},
{
"sys":{"id": "3"},
"fields":{
"title": "Web Development.",
"price": 14.99,
"image":{"fields":{"file":{"url":"back1.jpg"}}}
}
},
{
"sys":{"id": "4"},
"fields":{
"title": "Machine Learning Master course.",
"price": 541.99,
"image":{"fields":{"file":{"url":"back1.jpg"}}}
}
},
{
"sys":{"id": "5"},
"fields":{
"title": "Data Structure and Algorithms.",
"price": 954.99,
"image":{"fields":{"file":{"url":"back1.jpg"}}}
}
},
{
"sys":{"id": "6"},
"fields":{
"title": "Cyber Security.",
"price": 484.99,
"image":{"fields":{"file":{"url":"back1.jpg"}}}
}
},
{
"sys":{"id": "7"},
"fields":{
"title": "Data Analysis.",
"price": 554.99,
"image":{"fields":{"file":{"url":"back1.jpg"}}}
}
}
]
}
HTML File
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="webpage.css">
<title>Document</title>
</head>
<body>
<nav class="navbar">
<div class="burger">
<div class="layer1"></div>
<div class="layer2"></div>
<div class="layer3"></div>
</div>
<div class="logo">
<span class="logo-text"><i class="fa fa-book" style="margin-right: 0.1em"></i>Comfort<span
style="color:#f095d1" ; font-size: 1.1em;>Learning</span>
</div>
<div class="menubar">
<ul class="list">
<li class="list-items"><a href="#">Home</a></li>
<li class="list-items"><a href="#">Courses</a></li>
<li class="list-items"><a href="#">Pricing</a></li>
<li class="list-items"><a href="#">About Us</a></li>
</ul>
</div>
<div class="cart">
<i class="fa fa-shopping-cart fa-1x"></i>
<div class="number-of-items"><span class="noi">0</span></div>
</div>
</nav>
<section class="section1">
<div class="banner">
<h1>Find your favorite courses here</h1>
<a href="#product">Shop Now</a>
</div>
</section>
<section class="section 2" id="products">
<div class="title">
<h1>Courses We Offer!</h1>
</div>
<div class="product">
</div>
</section>
<div class="cart-sidebar">
<div class="cart">
<span class="close-cart">
<i class="fa fa-times"></i>
</span>
<h2>Your cart</h2>
<div class="cart-content"></div>
</div>
<div class="total-sum"></div>
<h1>Your total: $ <span class="total-amount">0</span></h1>
</div>
<div class="clear-cart">
<button class="btn clear-cart btn">Clear Cart</button>
</div>
<div class="clear-cart">
<button class="btn clear-cart-btn">Proceed</button>
</div>
</div>
</div>
<div class="menu-sidebar">
<div class="close-menu">
<i class="fa fa-times"></i>
</div>
<div class="menu-menubar">
<ul class="menu-list">
<li class="menu-list-items"><a href="#">Home</a></li>
<li class="menu-list-items"><a href="#">Category</a></li>
<li class="menu-list-items"><a href="#">Price</a></li>
<li class="menu-list-items"><a href="#">About</a></li>
</ul>
</div>
</div>
<script src="webpage.js" type="text/javascript"></script>
<script src="webpage.json" type="text/javascript"></script>
</body>
</html>
6 to 14 march taken to completed