Download presentation
Presentation is loading. Please wait.
Published byMyles Williamson Modified over 9 years ago
1
JavaScript- conditions, Math objects
2
Generic Representation
3
Condition If (a > b) { // some instructions here } If (a >= b) { // some instructions here } else { // some instructions here } If (a < b) { // some instructions here } else if (c == d) { // some instructions here } else { // additional instructions here }
4
Nested Conditions If (a <= b) { // some instructions here if (d == f) { some nested instructions } If (a != b) { // some instructions here } else { // some instructions here if (d == f) { some nested instructions }
5
Exercise: jex6.html Checking for null In this exercise below, when you reset the form and you click Total when both input box are empty, you displayed an “NAN” You need to check for null in the input box before you perform the addition or multiplication function. if (document.simpleForm.box1.value== "") { alert (“You need to have a value in the first box”); } else if (document.simpleForm.box1.value== "") { alert (“You need to have a value in the second box”); } else { // use the code from before to display the total }
6
Recall: Button and Response Make a button and a message box. Need to have a form to “hold” this GUI objects You write form instructions in the body. You write the javascript function in the head. Note the difference between ALERT and COFIRM function displayText() { document.simpleForm.response.value="You click the red button!"; }
7
Math objects Calculation sometimes require you to use mathematical functions such as a 3 requires you to use the power function such as Math.pow(a, 3). Examples are: Math.PI ~ Math.round(3.14) that rounds off a number Math.random() that gives you a floating pt. number between 0 and 1
8
Exercise: jex7.html Loan Calculator Get three input values, loan amount, yearly interest rate and Number of Years. Compute the monthly and total payments using formula below L: Loan Amount R: Monthly Interest Rate (YearlyRate / 12) N: Number of payment periods (NoYrs X 12) Output the results
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.