![]() |
Lesson Plan |
| IMOS Home | Student Center | TallTech Home |
December 9, 1999Details
Reading / ReferencesTutorial 7 - Programming with JavaScript - New Perspectives Manual (NP) |
Alert boxes
Prompts
Declare JavaScript externally
Look at some additional statements for more control.
Strings
Math functionality
Work through practice exercises
Checkpoint #3
JavaScript assignments
Using the previous exercises as a reference:
Take the updated weight converter add prompts asking the user for input
Add prompts to the area calculator
Add prompts to the record rainfall program
Add prompts to the loop exercise for the balance calculator
EXERCISE:
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from older browsers
var
InitBal = prompt("What is the initial balance?", 1000);
var
IntRate = prompt("What is the initial interest rate?", 12);
var
Months = prompt("Calculate for how many months?", 12);
document.write("Initial
balance: " + InitBal + "<BR>");
document.write("Interest
rate: " + IntRate + "<BR>");
document.write("Month Balance<BR>");
var
AccumBal = InitBal*1; //ensure that it is thinking it is a number
for(i=1;
i<=Months; i++)
{
AccumBal = AccumBal + (AccumBal * (IntRate/12/100) );
document.write(i);
document.write(" ");
document.write(AccumBal + "<BR>");
}
document.write("Final
balance is: " + AccumBal);
// End Hide -->
</SCRIPT>
</BODY>
</HTML>
Alert Boxes
alert ("A message to the user");
Prompting the user
var
myvariable = prompt("Question goes here?", "Default Value");
External references
<SCRIPT
LANGUAGE="Javascript" SRC="http://www.mydomain.com/myscript.js">
</SCRIPT>
Looping through an array – compatibility?
for count in myArray
{
write(myArray[count]);
}
Breaking out early
count = 0;
while (count < 10)
{
if (count == 5)
break;
write(count + "...");
count++;
}
Jumping to the next iteration
for iteration in myArray
{
if (Math.odd(iteration))
continue;
writeln(myArray[iteration]);
}
Strings
Concatenation
String methods
i.e. toUpperCase(), toLowerCase
changing attributes
Working with the math functions
Math functionality / methods
i.e. abs - absolute value, min, max, etc.