Back to Freecodecamp

Step 7

curriculum/challenges/english/blocks/learn-basic-oop-by-building-a-shopping-cart/63ec3287b182ec0efe8a3135.md

latest11.2 KB
Original Source

--description--

Following that same data structure, add the products from this table (in order) to your products array. Increment the id for each product, counting up.

namepricecategory
French Macaron3.99Macaron
Pumpkin Cupcake3.99Cupcake
Chocolate Cupcake5.99Cupcake
Chocolate Pretzels (4 Pack)10.99Pretzel
Strawberry Ice Cream2.99Ice Cream
Chocolate Macarons (4 Pack)9.99Macaron
Strawberry Pretzel4.99Pretzel
Butter Pecan Ice Cream2.99Ice Cream
Rocky Road Ice Cream2.99Ice Cream
Vanilla Macarons (5 Pack)11.99Macaron
Lemon Cupcakes (4 Pack)12.99Cupcake

--hints--

Your second object in the products array should have an id property set to the number 2.

js
assert.equal(products[1].id, 2);

Your second object in the products array should have a name property set to French Macaron.

js
assert.equal(products[1].name, 'French Macaron');

Your second object in the products array should have a price property set to the number 3.99.

js
assert.equal(products[1].price, 3.99);

Your second object in the products array should have a category property set to Macaron.

js
assert.equal(products[1].category, 'Macaron');

Your third object in the products array should have an id property set to the number 3.

js
assert.equal(products[2].id, 3);

Your third object in the products array should have a name property set to Pumpkin Cupcake.

js
assert.equal(products[2].name, 'Pumpkin Cupcake');

Your third object in the products array should have a price property set to the number 3.99.

js
assert.equal(products[2].price, 3.99);

Your third object in the products array should have a category property set to Cupcake.

js
assert.equal(products[2].category, 'Cupcake');

Your fourth object in the products array should have an id property set to the number 4.

js
assert.equal(products[3].id, 4);

Your fourth object in the products array should have a name property set to Chocolate Cupcake.

js
assert.equal(products[3].name, 'Chocolate Cupcake');

Your fourth object in the products array should have a price property set to the number 5.99.

js
assert.equal(products[3].price, 5.99);

Your fourth object in the products array should have a category property set to Cupcake.

js
assert.equal(products[3].category, 'Cupcake');

Your fifth object in the products array should have an id property set to the number 5.

js
assert.equal(products[4].id, 5);

Your fifth object in the products array should have a name property set to Chocolate Pretzels (4 Pack).

js
assert.equal(products[4].name, 'Chocolate Pretzels (4 Pack)');

Your fifth object in the products array should have a price property set to the number 10.99.

js
assert.equal(products[4].price, 10.99);

Your fifth object in the products array should have a category property set to Pretzel.

js
assert.equal(products[4].category, 'Pretzel');

Your sixth object in the products array should have an id property set to the number 6.

js
assert.equal(products[5].id, 6);

Your sixth object in the products array should have a name property set to Strawberry Ice Cream.

js
assert.equal(products[5].name, 'Strawberry Ice Cream');

Your sixth object in the products array should have a price property set to the number 2.99.

js
assert.equal(products[5].price, 2.99);

Your sixth object in the products array should have a category property set to Ice Cream.

js
assert.equal(products[5].category, 'Ice Cream');

Your seventh object in the products array should have an id property set to the number 7.

js
assert.equal(products[6].id, 7);

Your seventh object in the products array should have a name property set to Chocolate Macarons (4 Pack).

js
assert.equal(products[6].name, 'Chocolate Macarons (4 Pack)');

Your seventh object in the products array should have a price property set to the number 9.99.

js
assert.equal(products[6].price, 9.99);

Your seventh object in the products array should have a category property set to Macaron.

js
assert.equal(products[6].category, 'Macaron');

Your eighth object in the products array should have an id property set to the number 8.

js
assert.equal(products[7].id, 8);

Your eighth object in the products array should have a name property set to Strawberry Pretzel.

js
assert.equal(products[7].name, 'Strawberry Pretzel');

Your eighth object in the products array should have a price property set to the number 4.99.

js
assert.equal(products[7].price, 4.99);

Your eighth object in the products array should have a category property set to Pretzel.

js
assert.equal(products[7].category, 'Pretzel');

Your ninth object in the products array should have an id property set to the number 9.

js
assert.equal(products[8].id, 9);

Your ninth object in the products array should have a name property set to Butter Pecan Ice Cream.

js
assert.equal(products[8].name, 'Butter Pecan Ice Cream');

Your ninth object in the products array should have a price property set to the number 2.99.

js
assert.equal(products[8].price, 2.99);

Your ninth object in the products array should have a category property set to Ice Cream.

js
assert.equal(products[8].category, 'Ice Cream');

Your tenth object in the products array should have an id property set to the number 10.

js
assert.equal(products[9].id, 10);

Your tenth object in the products array should have a name property set to Rocky Road Ice Cream.

js
assert.equal(products[9].name, 'Rocky Road Ice Cream');

Your tenth object in the products array should have a price property set to the number 2.99.

js
assert.equal(products[9].price, 2.99);

Your tenth object in the products array should have a category property set to Ice Cream.

js
assert.equal(products[9].category, 'Ice Cream');

Your eleventh object in the products array should have an id property set to the number 11.

js
assert.equal(products[10].id, 11);

Your eleventh object in the products array should have a name property set to Vanilla Macarons (5 Pack).

js
assert.equal(products[10].name, 'Vanilla Macarons (5 Pack)');

Your eleventh object in the products array should have a price property set to the number 11.99.

js
assert.equal(products[10].price, 11.99);

Your eleventh object in the products array should have a category property set to Macaron.

js
assert.equal(products[10].category, 'Macaron');

Your twelfth object in the products array should have an id property set to the number 12.

js
assert.equal(products[11].id, 12);

Your twelfth object in the products array should have a name property set to Lemon Cupcakes (4 Pack).

js
assert.equal(products[11].name, 'Lemon Cupcakes (4 Pack)');

Your twelfth object in the products array should have a price property set to the number 12.99.

js
assert.equal(products[11].price, 12.99);

Your twelfth object in the products array should have a category property set to Cupcake.

js
assert.equal(products[11].category, 'Cupcake');

--seed--

--seed-contents--

html
<!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>freeCodeCamp Shopping Cart</title>
    <link rel="stylesheet" href="./styles.css" />
  </head>
  <body>
    <header>
      <h1 class="title">Desserts Page</h1>
    </header>
    <main>
      <button id="cart-btn" type="button" class="btn">
        <span id="show-hide-cart">Show</span> Cart
      </button>
      <div id="cart-container">
        <button class="btn" id="clear-cart-btn">Clear Cart</button>
        <div id="products-container"></div>
        <p>Total number of items: <span id="total-items">0</span></p>
        <p>Subtotal: <span id="subtotal">$0</span></p>
        <p>Taxes: <span id="taxes">$0</span></p>
        <p>Total: <span id="total">$0</span></p>
      </div>
      <div id="dessert-card-container"></div>
    </main>
    <script src="./script.js"></script>
  </body>
</html>
css
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --dark-grey: #1b1b32;
  --light-grey: #f5f6f7;
  --black: #000;
  --white: #fff;
  --grey: #3b3b4f;
  --golden-yellow: #fecc4c;
  --yellow: #ffcc4c;
  --gold: #feac32;
  --orange: #ffac33;
  --dark-orange: #f89808;
}

body {
  background-color: var(--dark-grey);
}

.title {
  color: var(--light-grey);
  text-align: center;
  margin: 25px 0;
}

#dessert-card-container {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-items: center;
}

.dessert-card {
  background-color: var(--light-grey);
  padding: 15px;
  text-align: center;
  border-radius: 15px;
  margin: 20px 10px;
}

.dessert-price {
  font-size: 1.2rem;
}

.btn {
  display: block;
  cursor: pointer;
  width: 100px;
  color: var(--dark-grey);
  background-color: var(--gold);
  background-image: linear-gradient(var(--golden-yellow), var(--orange));
  border-color: var(--gold);
  border-width: 3px;
}

.btn:hover {
  background-image: linear-gradient(var(--yellow), var(--dark-orange));
}

#cart-btn {
  position: absolute;
  top: 0;
  right: 0;
}

.add-to-cart-btn {
  margin: 30px auto 10px;
}

#cart-container {
  display: none;
  position: absolute;
  top: 60px;
  right: 0;
  background-color: var(--light-grey);
  width: 200px;
  height: 400px;
  border: 8px double var(--black);
  border-radius: 15px;
  text-align: center;
  font-size: 1.2rem;
  overflow-y: scroll;
}

.product {
  margin: 25px 0;
}

.product-count {
  display: inline-block;
  margin-right: 10px;
}

.product-category {
  margin: 10px 0;
}

@media (min-width: 768px) {
  #dessert-card-container {
    flex-direction: row;
  }

  .dessert-card {
    flex: 1 0 21%;
  }

  #cart-container {
    width: 300px;
  }
}
js
const cartContainer = document.getElementById("cart-container");
const productsContainer = document.getElementById("products-container");
const dessertCards = document.getElementById("dessert-card-container");
const cartBtn = document.getElementById("cart-btn");
const clearCartBtn = document.getElementById("clear-cart-btn");
const totalNumberOfItems = document.getElementById("total-items");
const cartSubTotal = document.getElementById("subtotal");
const cartTaxes = document.getElementById("taxes");
const cartTotal = document.getElementById("total");
const showHideCartSpan = document.getElementById("show-hide-cart");
let isCartShowing = false;

--fcc-editable-region--
const products = [
  {
    id: 1,
    name: "Vanilla Cupcakes (6 Pack)",
    price: 12.99,
    category: "Cupcake",
  },

];
--fcc-editable-region--