Click here to Skip to main content
15,908,115 members

Comments by Harvey.S (Top 3 by date)

Harvey.S 25-Aug-22 15:31pm View    
there is some issue with the javascript its not working

// grab everything we need
const priceInput = document.querySelector('[name=price]');
const quantityInput = document.querySelector('[name=quantity]');
const total = document.querySelector('.total');
const quantityLabel = document.querySelector('.quantity-label');
const discount = document.querySelector('.discount');

// create functions we'll need
function calculateCost() {
const price = priceInput.value;
const quantity = quantityInput.value;
const cost = price * quantity;
const discount = cost - (cost * 0.25)
console.log(cost);
total.innerText = "$" + cost.toFixed(2);

}

// create functions we'll need
function calculateDiscount() {
const discount = cost - (cost * 0.25)
console.log(discount);
total.innerText = "$" + discount.toFixed(2);

}

function updateQuantityLabel() {
const quantity = quantityInput.value;
quantityLabel.innerText = quantity;
}


// on first run
calculateCost();

// add event listeners
priceInput.addEventListener('input', calculateCost);
quantityInput.addEventListener('input', calculateCost);
quantityInput.addEventListener('input', updateQuantityLabel);
Harvey.S 25-Aug-22 12:55pm View    
I need to show the total amount and amount after discount separately
Harvey.S 25-Aug-22 11:39am View    
I didn't able to get the total after the deduction of discount amount