Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 21, 2021 03:28 pm GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To