Question: How to get functions on a Javascript calculator to display the answer or error message in the text box. In my code I am supposed
How to get functions on a Javascript calculator to display the answer or error message in the text box.
In my code I am supposed to get the squared (x^2), halve (1/2 whatever number is entered and then divided by 2), and area of circle (area) buttons functioning while also getting the answer of any calculation or error message (display if the formula entered cannot be converted) to display in the text box of the calculator and then once another button is clicked (for example, 4, it would clear everything out in that textbox and only display the number 4, thus allowing another formula to be entered).
So far I am able to get the buttons to do the proper functions, I just need help coding it so that once the equal button is clicked, it will display the answer or error message in the text box and then clear out the text once the user clicks another button and display the number the user entered to start a new formula.
below is my code:
calculator.html -
JS Calculator
JavaScript Calculator
JS-18X
calculator.js -
window.addEventListener("load", function() { document.getElementById("convertBtn").addEventListener("click", convert); //will get all button values var numbers = document.getElementsByClassName("digit"); var size = numbers.length; //gets length of array of numbers/button values //loops through and adds an event listener to each of the buttons for (var i = 0; i
**if you could put what changes I need to make in bold, I would appreciate it**
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
