When the add button is pressed, the number in the (0)Cart link should increase. When the remove button is pressed, the number should decrease. When I click on the link, it should take me to a checkout.html page. The checkout.html page should display all the items added in the cart, and a total price.  Existing code: products.html Products (0) Cart Price: $10 Name: Clorox Description: Household Product ID: product1 Add to cart Remove from cart Price: $15 Name: Oxiclean Description: Product Packaging ID: product2 Add to cart Remove from cart Price: $20 Name: Pinesol Description: Household Product ID: product3 Add to cart Remove from cart Price: $15 Name: Mr Clean Description: Household Product ID: product4 Add to cart Remove from cart Price: $10 Name: Windex Description: Household Product ID: product5 Add to cart Remove from cart   shoppingcart.js var cart=[]; var productArray=[]; productArray.push({Price:"$10",Name:"Clorox",Description:"Household Product",ID:"product1"}); productArray.push({Price:"$15",Name:"Oxiclean",Description:"Product Packaging",ID:"product2"}); productArray.push({Price:"$20",Name:"Pinesol",Description:"Household Product",ID:"product3"}); productArray.push({Price:"$15",Name:"Mr Clean",Description:"Household Product",ID:"product4"}); productArray.push({Price:"$10",Name:"Windex",Description:"Household Product",ID:"product5"}); function Add(id){ const index = productArray.findIndex(x => x.ID ===id); cart.push(productArray[index]); } function Remove(id){ const index = cart.findIndex(x => x.ID ===id); cart.splice(index, 1); document.getElementById("whereToPrint").innerHTML = JSON.stringify(cart, null, 4); return whereToPrint; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

When the add button is pressed, the number in the (0)Cart link should increase. When the remove button is pressed, the number should decrease. When I click on the link, it should take me to a checkout.html page. The checkout.html page should display all the items added in the cart, and a total price. 

Existing code:

products.html

<!DOCTYPE html>
<html>

<head>
<title>Products</title>
<script src="./js/shoppingcart.js"></script>
</head>

<body>
<div>
<div>
<a href="Checkout.html">
<span style="float:right"><p>(<span>0</span>) Cart</p></span>
</a>
</div>
<div class="product">
<img src="img/clorox.jpg">
<p class="price">Price: $10</p>
<p class="name">Name: Clorox</p>
<p class="description">Description: Household Product</p>
<p class="id">ID: product1</p>
<span><button id="product1">
Add to cart
</button>
<button>
Remove from cart
</button>
</span>
</div>
<br>
<div class="product">
<img src="img/oxiclean.jpg">
<p class="price">Price: $15</p>
<p class="name">Name: Oxiclean</p>
<p class="description">Description: Product Packaging</p>
<p class="id">ID: product2</p>
<span><button id="product2">
Add to cart
</button>
<button>
Remove from cart
</button>
</span>
</div>
<br>
<div class="product">
<img src="img/pinesol.jpg">
<p class="price">Price: $20</p>
<p class="name">Name: Pinesol</p>
<p class="description">Description: Household Product</p>
<p class="id">ID: product3</p>
<span><button id="product3">
Add to cart
</button>
<button>
Remove from cart
</button>
</span>
</div>
<br>
<div class="product">
<img src="img/mrclean.jpg">
<p class="price">Price: $15</p>
<p class="name">Name: Mr Clean</p>
<p class="description">Description: Household Product</p>
<p class="id">ID: product4</p>
<span><button id="product4">
Add to cart
</button>
<button>
Remove from cart
</button>
</span>
</div>
<br>
<div class="product">
<img src="img/windex.jpg">
<p class="price">Price: $10</p>
<p class="name">Name: Windex</p>
<p class="description">Description: Household Product</p>
<p class="id">ID: product5</p>
<span><button id="product5">
Add to cart
</button>
<button>
Remove from cart
</button>
</span>
</div>
<br>

</div>

<pre id="whereToPrint"></pre>

</body>

</html>

 

shoppingcart.js

var cart=[];

var productArray=[];
productArray.push({Price:"$10",Name:"Clorox",Description:"Household Product",ID:"product1"});
productArray.push({Price:"$15",Name:"Oxiclean",Description:"Product Packaging",ID:"product2"});
productArray.push({Price:"$20",Name:"Pinesol",Description:"Household Product",ID:"product3"});
productArray.push({Price:"$15",Name:"Mr Clean",Description:"Household Product",ID:"product4"});
productArray.push({Price:"$10",Name:"Windex",Description:"Household Product",ID:"product5"});


function Add(id){
const index = productArray.findIndex(x => x.ID ===id);
cart.push(productArray[index]);

}
function Remove(id){
const index = cart.findIndex(x => x.ID ===id);
cart.splice(index, 1);

document.getElementById("whereToPrint").innerHTML = JSON.stringify(cart, null, 4);
return whereToPrint;
}

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Image Element
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education