Jehr's Homeworks

First Exercise

Produce a web page that allows on-line applicants to check their credit limit. The solution should use an if else if .. .. else construct.
  • Users are required to enter their income into a text box txtIncome.
  • Users are required to enter their age into a text box txtAge.
  • Users click an Estimate Credit button (cmdEstimateCredit) that will calculate and display (in pounds and pence) the credit limit of the applicant in a text box txtCreditLimit.
Credit Limit is calculated as follows
  • Under 18 years old ZERO credit
  • 18 years to 25 years inclusive 1 x income
  • 26 years or older 3 x income

Like this:

Credit Limit Checker

Solution

<SCRIPT type="text/javaScript">
function button1Listener()
			{
				
				
				var credit;
				var income= parseFloat(document.getElementById("txtIncome").value);
				var age= parseFloat(document.getElementById("txtAge").value);
				if (isNaN(income)) alert("Income must be an  numeric. Please Re-enter");
				else if (isNaN(age)) alert("Age must be an integer. Please Re-enter");		
				     else if (age<18) credit=0;
				          else if (age < 26) credit=income;
					       else credit=3.0*income;
				document.getElementById("txtCreditLimit").value = '\u00A3'+ credit;
			
			}
			
			
			function doit()
			{
				
				//alert("hello");
				var  btn1=document.getElementById("cmdEstimateCredit");
				btn1.addEventListener("click",
							button1Listener,
							false
						      );

			}
		</SCRIPT>