I'm making a simple calculator and my function is not working:
HTML:
<div id="mathLine">0</div>
<div id="score">none</div>
<button id="clear" class = "num" ocnlick="clear(0)">C</button>
<button id="exp" class = "num" >exp</button>
<button id="sqrt" class = "num">sqrt</button>
<button id="buttonide" class = "num">/</button>
<button id="seven7" class = "num" onclick="numerical(7)">7</button>
<button id="eight8" class = "num" onclick="numerical(8)">8</button>
<button id="nine9" class = "num" onclick="numerical(9)">9</button>
<button id="multiply" class = "num" onclick="numerical('X')">X</button>
JS
var equation = [];
function numerical(number){
equation.push(number);
document.getElementById('mathLine').innerHTML = equation;
console.log(equation);
};
function clear (j) {
for (j; j < (equation.length+2); j++){
equation.pop();
}
console.log(equation);
document.getElementById('mathLine').innerHTML = "0";
};
Some more info:
- js file is correctly implemented in html;
- the first function (numerical) is working fine;
- List item when I tried it in separate html file, where I put html and js in tag it all worked
So I have no idea, what's wrong... Maybe I'm looking at it too long and I'm not seeing something obvious?
.innerHTMLis not working as expected. It sounds like the mathLine's text does not change.