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

£ per anmum

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()
			{
				
				var  btn1=document.getElementById("cmdEstimateCredit");
				
				btn1.addEventListener("click",
							button1Listener,
							false
						      );


			}



</SCRIPT>

Second Exercise

Produce a suitable web page containing a command button called cmdFindMaximum. This button, when clicked, should implement the following pseudo-code: initialize a maximum value to be 0 repeat a loop 5 times ask the user to input a measurement less than 10 if the maximum value is smaller than the input measurement then the maximum value becomes the input measurement end if end loop output the maximum measurement with a suitable message N.B. You are not required to implement any error-checking code for the input of the measurement. Like this:

Solution

<SCRIPT type="text/javaScript">
						
			function maxButtonListener()
			{
				
					
				var max=0;
				for (var i=0;i<5;i++)
				{
					var n=prompt("Enter a number")
					if (n>max) max=n;
				}
			
				alert ("the biggest was " +n);
			}
			
			
			
			function doit()
			{
				
				
				var  btn1=document.getElementById("cmdEstimateCredit");
				btn1.addEventListener("click",
							button1Listener,
							false
						      );
				
			  // you must add the maxButtonListner to the maxButton here!
				
				

			}
	
			


</SCRIPT>