Extra Credit - Javascript Financial Calculator
LABAR Extra Credit Project
This
assignment is to be done during your one hour lab by arrangement
(LABAR). This assignment requires you to write your first javascript to
declare, assign and display three variables of the string, number, and boolean types respectively.
In this extra credit assignment, you are to create a compound interest payment calculator as in the example below that takes the loan amount, term, and apr interest in HTML FORM, and have a submit button to calculate the payment. The annual APR interest is a compound calculation, that the annual interest shall become capital. Here is a demo Interest Calculator:
You may implement the solution using the following code examples:
1. Type cast the input type to number
javascript to read and convert the input text string from coresponding html FORM text INPUT to an integer variable:
var years = parseInt(document.block.par.value);
// parseInt is the function converts string to integer
// document is the built-in object, like document.write
// block is the html form name below
// par is the html input name below
// parseInt is the function converts string to integer
// document is the built-in object, like document.write
// block is the html form name below
// par is the html input name below
corresponding html:
<form id="block" name="block">
<input type="text" name="par"/>
...
</form>
<input type="text" name="par"/>
...
</form>
javascript to write the result to corresponding html FORM text INPUT:
document.blog.par.value=result;
2. html FORM text INPUT
to disallow the user to alter its value:
<input name="name_of_input_field" disabled="disabled" type="text" />
to act as a button on mouse click perform javascript function:
<input onclick="function();" type="submit" value="Label" />
// type has to be "submit"
// "function();" should be "the_name_of_your_function();"
// "Label" should be "the_button_label_to_be_displayed_on_screen"
// type has to be "submit"
// "function();" should be "the_name_of_your_function();"
// "Label" should be "the_button_label_to_be_displayed_on_screen"
3. javascript function declaration:
function name_of_the_function(par1,par2,...) {
...
}
...
}
4. javascript defensive programing
In case the user enters a text string instead of number, the following script would reset the variable to default value:
if((variable <= 0)||(isNaN(variable))) variable = 1; // isNaN() returns true if the number variable is not a number // in this example, the default value is 1
5. an example formula is shown in the following example:
for( i=term; i>0; i--){
principal = principal*(1 + apr/100);
}
payment = principal/term;
principal = principal*(1 + apr/100);
}
payment = principal/term;
Assignment 10 - Javascript Simple Calculator (PL's note js pages 16 to 27)
LABAR Project 10
This
assignment is to be done during your one hour lab by arrangement
(LABAR). This assignment requires you to write your first javascript to
declare, assign and display three variables of the string, number, and boolean types respectively.
In this assignment, Assignment #10, you are to create a simple calculator as in the HTML Form below. This calculator can:
- add, substract, multiply, and divide the two numbers entered;
- after the math operator button is pressed, the result shall be placed inside the Answer field;
- after the Clear, "C" button is pressed, all fields shall be cleared.
The above html form code is listed below:
Sample Code:
Javascript Adder Try this adder out!
Simple Adder
Assignment 9 - Javascript Decision Statement and Input Box (PL's note js p.10 - 14)
LABAR Project 9
This
assignment is to be done during your one hour lab by arrangement
(LABAR). This assignment requires you to create a javascript function to take in two variables and print the difference if the first one is larger, else print the sum:
Step 1 - declare two number variables: var1 and var2;
Step 2 - prompt and obtain the value of var1 then var2 (one at a time) and print both variables on the screen;
Step 3 - if the var1 is greater than var2 , then print the difference of var1 and var2, else print the sum of var1 and var2.
And use an html tag onclick attribute to envoke this javascript function.
Note: The following envelope HTML code has to be included for the .html file in order for your javascript to execute correctly:
Example
The following javascript example can be found on the PL's note p.11
Click the button to execute the sample javascript:
Assignment 8 - Flowchart to Javascript
Posted by
COMSC DVC
at
6:07 AM
LABAR Project 8
This
assignment
is to be done during your one hour lab by arrangement
(LABAR). This assignment requires you to create a javascript from a flowchart. This assignment is to ensure that you learn how to better write javascript through the flowchart, especially the flow control.
And use an html tag onclick attribute to envoke this javascript function.
Note: The following envelope HTML code has to be included for the .html file in order for your javascript to execute correctly:
Assignment 7 - Javascript variables (PL's note js pages 1 to 9)
LABAR Project 7
This assignment is to be done during your one hour lab by arrangement (LABAR). This assignment requires you to write your first javascript to declare, assign and display three variables of the string, number, and boolean types respectively.
Variables (on page 3 of PL's note) are entities that can change. In this assignment, you are to write your first javascript.
- Frist, declare 3 variables: var1, var2, and var3 as the string, number, and boolean types respectively.
- Next, print the value of all (3) variables.
- Then, assign new values to all (3) variables. Then, print the value of all (3) variables.
Please submit your javascript work in .html file through webCT-assignment.
Note: The following envelope HTML code has to be included for the .html file in order for your javascript to execute correctly:
Example
place the example here




