html - Three things I don't understand about this javascript calculator -
hey i'm new javascript , wondering bit of code never saw , wondering how worked practice javascript wanted make calculator , got code online wondering 3 things.
how code know output number , answer text box.
how line of code work?
calc.input.value
knowcalc
forminput
input ,value
value of input 1 2 or 3 how in know input i'm choosing?what
calc.input.value = eval(calc.input.value)
, how work?
thanks time , have nice day , sorry if didn't give enough info.
<form name="calc"> <table border=4> <tr> <td> <input type="text" name="input" size="16"> <br> </td> </tr> <tr> <td> <input type="button" name="one" value=" 1 " onclick="calc.input.value += '1'"> <input type="button" name="two" value=" 2 " onclick="calc.input.value += '2'"> <input type="button" name="three" value=" 3 " onclick="calc.input.value += '3'"> <input type="button" name="plus" value=" + " onclick="calc.input.value += ' + '"> <br> <input type="button" name="four" value=" 4 " onclick="calc.input.value += '4'"> <input type="button" name="five" value=" 5 " onclick="calc.input.value += '5'"> <input type="button" name="six" value=" 6 " onclick="calc.input.value += '6'"> <input type="button" name="minus" value=" - " onclick="calc.input.value += ' - '"> <br> <input type="button" name="seven" value=" 7 " onclick="calc.input.value += '7'"> <input type="button" name="eight" value=" 8 " onclick="calc.input.value += '8'"> <input type="button" name="nine" value=" 9 " onclick="calc.input.value += '9'"> <input type="button" name="times" value=" x " onclick="calc.input.value += ' * '"> <br> <input type="button" name="clear" value=" c " onclick="calc.input.value = ''"> <input type="button" name="zero" value=" 0 " onclick="calc.input.value += '0'"> <input type="button" name="doit" value=" = " onclick="calc.input.value = eval(calc.input.value)"> <input type="button" name="div" value=" / " onclick="calc.input.value += ' / '"> <br> </td> </tr> </table> </form>
- see
onclick
attribute: if it's clicked, execute code inonclick
. actual value of input modified these+=
(append to). (if current input6 +
, click4
,4
appended:6 + 4
) input
here equivalentname
attribute of first input, that's why it's chosen.eval(calc.input.value)
interpreting value of input javascript. when there4 + 6
in input, it'll evaluated javascript , return10
.
Comments
Post a Comment