With our knowledge of Booleans, numbers, and strings, let's build a basic calculator. Begin by cloning the repository at https://github.com/PacktPublishing/Hands-on-JavaScript-for-Python-Developers/tree/master/chapter-4/calculator/starter-code.
You can safely ignore the HTML and CSS for the most part, but a readthrough of the HTML will help. Let's take a look at the JavaScript:
window.onload = (() => {
const buttons = document.getElementsByTagName('button')
const output = document.getElementsByTagName('input')[0]
let operation = null
let expression = firstNumber = secondNumber = 0
output.value = expression
const clickHandler = ((event) => {
let value = event.target.value
/** Write your calculator logic here.
Use conditionals and math to modify the output variable.
Example of how to use the operators object:
operators['='](1, 2) // returns 3
Expected things to use...