An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
April 21, 2021 03:28 pm GMT
Original Link: https://dev.to/dipayan108/make-a-calculator-with-pure-html5-css3-and-javascript-6gg
Make a calculator with pure HTML5 CSS3 and JavaScript!
so, recently i made a calculator with html, css and js ! to add it to my portfolio
**code for js for operator **
function useOperator(operator) { const currentValue = Number(calculatorDisplay.textContent) // Prevent multiple operators if (operatorValue && awaitingNextValue) { operatorValue = operator return } // Assign firstValue if no value if (!firstValue) { firstValue = currentValue; } else { const calculation = calculate[operatorValue](firstValue, currentValue) calculatorDisplay.textContent = calculation firstValue = calculation } // Ready for next value, store operator awaitingNextValue = true; operatorValue = operator;}
*** for add event listener ***
// Add Event Listeners for numbers, operators, decimal buttonsinputBtns.forEach((inputBtn) => { if (inputBtn.classList.length === 0) { inputBtn.addEventListener('click', () => sendNumberValue(inputBtn.value)) } else if (inputBtn.classList.contains('operator')) { inputBtn.addEventListener('click', () => useOperator(inputBtn.value)) } else if (inputBtn.classList.contains('decimal')) { inputBtn.addEventListener('click', () => addDecimal()) }})
Original Link: https://dev.to/dipayan108/make-a-calculator-with-pure-html5-css3-and-javascript-6gg
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To