1 / 8

JavaScript- conditions, Math objects

JavaScript- conditions, Math objects. Generic Representation. 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 {

grupp
Download Presentation

JavaScript- conditions, Math objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaScript- conditions, Math objects

  2. Generic Representation

  3. 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 } Condition

  4. 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 } } Nested Conditions

  5. Exercise: jex6.htmlChecking 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. 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. <FORM name=simpleForm> <input type="button" name="button1" value="RED" onclick="displayText()"> <BR> <TEXTAREA name="response" rows=3 cols=27> </textarea> <INPUT type="reset" value="Reset Form"> Recall: Button and Response function displayText() { document.simpleForm.response.value="You click the red button!"; } Note the difference between ALERT and COFIRM

  7. Math objects • Calculation sometimes require you to use mathematical functions such as a3 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.htmlLoan 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

More Related