I am designing my own JavaScript calculator with HTML values that look like this:
<input type="button" class="button gray"
value="tan" onclick='tan()'>
<input type="button" class="button black" value="3"
onclick='v("3")'>
And the JavaScript code looks something like this:
function tan() {
var getValue = document.getElementById("d").value;
document.getElementById("d").value=Math.tan(getValue);
}
function v(val) {
document.getElementById("d").value+=val;
}
Where the ID "d" represents the screen in which the values from the buttons one presses are entered.
Where I'm having trouble is having a button utilize the Math.pow(a,b) function. Once you press the button with the value x^y I want these steps to be taken:
- Take the value from element "d"
- Take the value from the next button pressed and enter that as the second value in the Math.pow() function.
I've got step one down, I just haven't figured out step two. The JavaScript code I envision is something like this:
function power() {
var getValue = document.getElementById("d").value;
......
......
var powerTotal = Math.pow(getValue,nextValue);
document.getElementById("d").value = powerTotal;
}
(getValue is the initial value, nextValue is the value of the next button pressed after the power button is pressed)
Thank you for your help in advance!!!
x, 2. click pow, 3. input second numbery, 4. click some kind of=button, 5. display result ofMath.pow(x, y)?