Untitled

mail@pastecode.io avatar
unknown
javascript
a month ago
740 B
1
Indexable
Never
let input = document.getElementById('inputbox')
let buttons = document.querySelectorAll('button')
let string = "";
let arr = Array.from(buttons);
arr.forEach((button) => {
    button.addEventListener('click', (event) => {
        if (event.target.innerHTML == '=') {
            string = eval(string);
            input.value = string;
        }
        else if(event.target.innerHTML == 'AC') {
            string = "";
            input.value = string;
        }
        else if(event.target.innerHTML == 'DEL') {
            string = string.substring(0, string.length-1)
            input.value = string;
        }
        else {
            string = string + event.target.innerHTML;
            input.value = string;
        }
    })
})
Leave a Comment