Create a new page called checkout.html that will display items that you added to the cart from product.html and a total price.
Existing code:
product.html
<!DOCTYPE html>
<html>
<head>
<script src="./js/cart.js"></script>
</head>
<body>
<div>
<div>
<a href="Checkout.html">
<span style="float:right"><p>(<span id="productCount">0</span>) Cart</p>
</span>
</a>
</div>
<div id="product1" class="card">
<img src="img/clorox.jpg">
<h1>Clorox</h1>
<p class="price">$20.00</p>
<p>Household Cleaner</p>
<p><button id="product1Btn1" onclick="addtocart(1)">Add to Cart</button></p>
<p><button id="product1Btn2" onclick="removecart(1)">Remove from Cart</button></p>
</div>
<div id="product2" class="card">
<img src="img/oxiclean.jpg">
<h1>Oxiclean</h1>
<p class="price">$8.00</p>
<p>Household Cleaner</p>
<p><button id="product2Btn1" onclick="addtocart(2)">Add to Cart</button></p>
<p><button id="product2Btn2" onclick="removecart(2)">Remove from Cart</button></p>
</div>
<div id="product3" class="card">
<img src="img/pinesol.jpg">
<h1>PineSol</h1>
<p class="price">$11.00</p>
<p>Household Cleaner</p>
<p><button id="product3Btn1" onclick="addtocart(3)">Add to Cart</button></p>
<p><button id="product3Btn2" onclick="removecart(3)">Remove from Cart</button></p>
</div>
<div id="product4" class="card">
<img src="img/mrclean.jpg">
<h1>Mr Clean</h1>
<p class="price">$12.00</p>
<p>Household Cleaner</p>
<p><button id="product4Btn1" onclick="addtocart(4)">Add to Cart</button></p>
<p><button id="product4Btn2" onclick="removecart(4)">Remove from Cart</button></p>
</div>
<div id="product5" class="card">
<img src="img/windex.jpg">
<h1>Windex</h1>
<p class="price">$15.00</p>
<p>Household Cleaner</p>
<p><button id="product5Btn1" onclick="addtocart(5)">Add to Cart</button></p>
<p><button id="product5Btn2" onclick="removecart(5)">Remove from Cart</button></p>
</div>
</body>
</html>
cart.js
const product = [{
id: 1,
name: "Clorox",
price: "$20.00",
image: "img/clorox.jpg",
category: "Household Cleaner",
},
{
id: 2,
name: "Oxiclean",
price: "$8.00",
image: "img/oxiclean.jpg",
category: "Household Cleaner",
},
{
id: 3,
name: "PineSol",
price: "$11.00",
image: "img/pinesol.jpg",
category: "Household Cleaner",
},
{
id: 4,
name: "Mr Clean",
price: "$12.00",
image: "img/mrclean.jpg",
category: "Household Cleaner",
},
{
id: 5,
name: "Windex",
price: "$15.00",
image: "img/windex.jpg",
category: "Household Cleaner",
},
];
var cart = new Array();
function addtocart(productid) {
for (var i = 0, iLen = product.length; i < iLen; i++) {
if (product[i].id == productid) {
cart.push(product[i].id);
}
}
console.log(cart);
document.getElementById("productCount").innerHTML = cart.length;
}
function removecart(productid) {
const index = cart.indexOf(productid);
if (index > -1) {
cart.splice(index, 1);
}
document.getElementById("productCount").innerHTML = cart.length;
console.log(cart);
}
Step by stepSolved in 4 steps with 1 images
- <!DOCTYPE html><html><head><title>Contact me</title></head><body><!--Added main tag--><main><!--Added nav tag--> <nav> <a href="home.html">Home</a> <a href="contact.html">Contact</a> <a href="about.html">About</a> </nav> <main><h1>Contact ME</h1></main> <picture> <source media="(min-width:650px)" srcset="me1-650.jpg"> <source media="(min-width:465px)" srcset="me1-465.jpg"> <img src="me1.jpg" alt="lake" style="width:auto;"> </picture> <p>You can contact me through : </p><div> <ul> <li>Email - 332boyman@gmail.com</li> <li>Phone - (802)3730290</li></ul> <footer> <p>Author: Josiah McSweeney<br><!--Added footer tag--><footer> <p>Copyright Reserved</p> </div>…arrow_forwardwhich element can be appropriately placed within a <p> element? 1) <em> 2) <html> 3) <meta> 4) <title>arrow_forward<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>Black Goose Bistro Summer Menu</title> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Marko+One&display=swap" rel="stylesheet"> <style> body { font-family: 'Open Sans', sans-serif; } h1{ font-family: 'Marko One', serif; } </style> </head> <body> <div id="info"> <h1>Black Goose Bistro • Summer Menu</h1> <p>Baker's Corner, Seekonk, Massachusetts<br> <span class="label">Hours: Monday through Thursday:</span> 11 to 9, <span class="label">Friday and…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY