Hello again,
I’m encountering a second issue with the Js calculator project.
What can I do not to overwrite the result of the expression by the sqrt method. I want the expression to be evaluated in the end by the result function…
function result() {
const result = getElementById("result");
let x = calcs.textContent;
x = eval(x);
result.textContent = x;
}
<div id="screenZone">
<div id="calculations"></div>
<div id="result"></div>
</div>
...
<input type="button" class="smallKey" value="√" disabled onclick="addToScreenZone('√')">
...
function addToScreenZone(x) {
let exp = calcs.textContent;
calcs.textContent += x;
let sqrtIndex = exp.indexOf('√');
if(sqrtIndex != -1) {
let num = parseInt(calcs.textContent.slice(sqrtIndex+1)); //not including the sqrt symbol to the string and then parsing it into an integer
getElementById("result").textContent = Math.sqrt(num); //overwriting the div with the id result
}
...
Any help would be greatly appreciated.