const prices = [...document.querySelectorAll(".order-info .price")]
.map(price => +price.textContent.replace(/[^\d|.]/g, "")) // get rid of text and $
const sum = prices.length > 0 ? prices.reduce((a, b) => a + b) : 0; // sum the array of prices - if none, then 0
console.log(sum.toFixed(2)); // sum of prices
const costs = [...document.querySelectorAll(".cost_sum div")];
const total = costs.length > 0 ? costs.reduce((acc, cost) => {
acc += +cost.textContent.replace(/[^\d|.]/g, "");
return acc;
}, 0) : 0;
console.log(total.toFixed(2))
body {
background-color: #424242;
}
.icon-container {
text-align: center;
}
.fa,
.fab {
font-size: 3.125em;
}
.fa-heart {
color: #ffffd !important;
}
.fa-cc-apple-pay {
background: -webkit-linear-gradient(45deg, rgb(119, 119, 119), rgb(255, 255, 255));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.fa-cc-mastercard {
background: -webkit-linear-gradient(0deg, #ffef00, #ff6f00, #ff0000);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.fa-cc-visa {
background: -webkit-linear-gradient(90deg, rgb(255, 255, 0), rgb(255, 255, 255), rgb(35, 38, 250));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.fa-cc-paypal {
background: -webkit-linear-gradient(45deg, rgb(0, 4, 255), rgb(0, 225, 255));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.fa-cc-amazon-pay {
background: -webkit-linear-gradient(45deg, rgb(255, 138, 4), rgb(255, 174, 0));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.fa-google-pay {
background: -webkit-linear-gradient(0deg, rgb(255, 0, 0), rgb(241, 147, 40), rgb(5, 206, 22), rgb(0, 174, 255));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.order-info-content .fa-shopping-cart {
color: #212121;
}
/* Main body of checkout section */
.checkout-tabs {
height: 59em;
width: 75.000em;
background: #fff;
display: flex;
border-radius: 2.063em;
}
@media only screen and (max-width: 700px) {
.checkout-tabs {
height: 62em;
}
}
/*
========================================================================================================
Payment Form
========================================================================================================
*/
.payment-form h2 {
margin-bottom: 0em;
margin-top: 1.563em;
text-align: center;
font-weight: 200;
font-size: 1.2em;
}
.order-info-content h2 {
margin-bottom: 0em;
text-align: center;
font-weight: 500;
font-size: 1.5em;
color: #212121;
}
.payment-form label {
margin-bottom: 0.625em;
display: block;
color: #ffffd;
}
.payment-form {
justify-content: center;
align-items: center;
display: flex;
}
.order-table .product-name {
font-weight: 500;
}
.order-table .description {
font-weight: 200;
font-size: 0.750em;
font-size: .8em;
list-style-type: none;
}
.half-input-table {
border-collapse: collapse;
width: 100%;
}
.half-input-table td:first-of-type {
border-right: 0.625em solid #212121;
width: 50%;
}
.order-info {
height: 100%;
width: 50%;
padding-left: 1.563em;
padding-right: 1.563em;
position: relative;
}
.price {
bottom: 0em;
position: absolute;
right: 0em;
color: #21212180;
}
.order-table td:first-of-type {
width: 25%;
}
.order-table {
position: relative;
}
.devider {
height: 0.063em;
width: 100%;
margin-top: 0.625em;
margin-bottom: 0.625em;
background: #21212185;
}
.cost_sum {
float: right;
text-align: right;
}
.total-field {
width: 50%;
margin-bottom: 20px;
}
.quantity {
width: 10%;
margin-left: 5px;
float: right;
}
.price-right {
float: right;
}
.checkout-button {
border: solid;
border-color: rgba(221, 221, 221, 0.281);
background: rgb(53, 53, 53);
padding: 0.7em;
border-radius: 1.250em;
font-size: 1.250em;
color: rgb(255, 255, 255);
cursor: pointer;
width: 100%;
}
.checkout-button:hover {
opacity: 95%;
}
.total-font {
line-height: 1.2em;
font-size: 1.000em;
font-size: 1em;
font-weight: 400;
}
.input-field {
background: #ffffd;
margin-bottom: 0.625em;
margin-top: 0.188em;
line-height: 1.5em;
font-size: 1.250em;
font-size: 1.3em;
border: none;
border-radius: 0.313em;
padding: 0.313em 0.625em 0.313em 0.625em;
color: #fff;
box-sizing: border-box;
width: 100%;
margin-left: auto;
margin-right: auto;
}
.details-field {
background: #212121;
height: 100%;
width: 50%;
color: #eee;
justify-content: center;
font-size: 0.875em;
font-size: .9em;
box-sizing: border-box;
padding-left: 1.563em;
padding-right: 1.563em;
border-radius: 1.875em;
border-style: solid;
border-color: white;
}
.details-inputs {
margin-top: 1.563em;
-webkit-flex-flow: column;
-ms-flex-flow: column;
flex-flow: column;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 100%;
}
.details-inputs h3 {
text-align: center;
padding: 0em;
margin-top: 0em;
font-size: large;
}
.item-btn {
color: red;
background-color: transparent;
border-style: none;
float: right;
}
.item-btn:hover {
cursor: pointer;
}
.checkout-form-1 {
height: 300px;
width: 400px;
margin: 20px auto;
border: 2px solid black;
text-align: center;
background-color: white;
}