bensei
8/6/2019 - 10:22 AM

Calculator

jQuery(function() {
  var truncates = jQuery('.calculator');
	 if (truncates.length) {
		const priceInput = document.querySelector('[name=price]');
        const quantityInput = document.querySelector('[name=quantity]');
        const total = document.querySelector('.total');
    
	
		const priceInputHall = document.querySelector('[name=priceh]');
        const quantityInputHall = document.querySelector('[name=quantityh]');
		const quantityInputHall2 = document.querySelector('[name=quantityh2]');
        const totalh = document.querySelector('.totalh');
  


        // create the functions that we'll need
        function calculatePieCost() {
            const price = 15;
            const quantity = quantityInput.value;
            const cost = price * quantity.replace(/\,/g, '.');
            console.log(cost);
            total.innerText = '€' + cost.toFixed(2);
        }
	
	
        // create the functions that we'll need
        function calculateHallCost() {
            const priceh = 6.95;
            const quantityh = quantityInputHall.value;
			const quantityh2 = quantityInputHall2.value;
            const costh = priceh * quantityh.replace(/\,/g, '.') * quantityh2.replace(/\,/g, '.');
            console.log(costh);
            totalh.innerText = '€' + costh.toFixed(2);
        }


        function updateQuantityLabel() {
            const quantity = quantityInput.value;
            quantityLabel.innerText = quantity;
        }
	
	     function updateQuantityLabelHall() {
            const quantityh = quantityInputHall.value;
            quantityLabelHall.innerText = quantityh;
        }

        // on first run
        calculatePieCost();

 		calculateHallCost();

        // add our event listeners
        priceInput.addEventListener('input', calculatePieCost);
        quantityInput.addEventListener('input', calculatePieCost);
	
	        priceInputHall.addEventListener('input', calculateHallCost);
        quantityInputHall.addEventListener('input', calculateHallCost);
	 quantityInputHall2.addEventListener('input', calculateHallCost);
   }    
});