Note the following function description and the use
of
the global function parseInt which converts strings of numeric
characters to numbers.
When the user enters anything into a text box on the screen it is in
the
form of alphanumeric characters (numerals not numbers) and hence cannot
be used
for calculations until numerals are converted into numbers by the
following built in function called parseInt. Notice javascript is case
sensitive and the middle "I" in parseInt must be a capital.
function
addIt() {
var
value1 = parseInt(document.adder.inputA.value)
var
value2 = parseInt(document.adder.inputB.value)
var
Total = value1 + value2
document.adder.output.value
= Total
}
Q2. Use the internet to find examples of javascript
calculators
and find a fully working
"on screen" / web calculator.
Try "webdeveloper.com".
a) Download and save a javascript calculator and embed it into your answer page. Instructions for doing this can be found on most javascript download pages. Again you copy and paste the script into the HTML inside the <language = Javascript> HTML tag.
Examine its javascripts. Most calculators will use the "eval() " function to do the calculation.
b) Research the eval() function in the textbook/s. What does the "eval()" function do ( explain how it works or what it does in general).
Write your answer on the web page you are using for
your
answers.
Q2 a)