Hi all,
I'm still in the beginning stages of JS, so I really don't know how to do this.
I'm trying to create a calculator, which I did, but I couldn't get the % to work.
I thought maybe I could use the operator(s) to invoke some kind of function to put what was typed into a variable and then create a new variable for the next numbers instead of just evalutating one big string at the beginning.
Here's where my head is right now:
Does anyone know where I can find some material on how to do this or can point me in the right direction?
Thanks,
Adam
I'm still in the beginning stages of JS, so I really don't know how to do this.
I'm trying to create a calculator, which I did, but I couldn't get the % to work.
I thought maybe I could use the operator(s) to invoke some kind of function to put what was typed into a variable and then create a new variable for the next numbers instead of just evalutating one big string at the beginning.
Here's where my head is right now:
Code:
<script type="text/javascript">
var num[i]
num[i] = document.calc.input.value
function add() {
if (i > 0) {
...
}
else {
alert('There is nothing to add')
}
}
Honestly, I have no idea what I'm doing here. I'm trying to get it to create a new num when an operator button is pressed, hold the value of the text box, then clear the text box for the next number. Pretty much like a desk calculator or the one used with Windows.
</script>
<html>
( just for reference.. there's a lot more but I'm using a diff computer to type this)
<form name="calc">
<input type="text" name="input">
<input type="button" value="+" id="operator" onClick="add()">
</html>
Thanks,
Adam
Comment