date
play

DATE CHANGES OUTSIDE FORMS CONDITIONALS IF THEN ELSE if (MUST - PowerPoint PPT Presentation

CONDITIONALS DATE CHANGES OUTSIDE FORMS CONDITIONALS IF THEN ELSE if (MUST BE LOWERCASE) No else: do nothing if not true else: one or the other else if: nested function OPERATORS Conditional Operator Meaning


  1. CONDITIONALS DATE CHANGES OUTSIDE FORMS

  2. CONDITIONALS

  3. IF … THEN … ELSE • if (MUST BE LOWERCASE) • No else: do nothing if not true • else: one or the other • else if: nested function

  4. OPERATORS Conditional Operator Meaning && and Operator Meaning || or == Is equal to ! not != Is not equal > Is greater than Logical < Is less than >= Is greater than or equal to <= Is less than or equal to

  5. CONDITIONAL EXAMPLE Random message using if Simple if…then…else Condition is random function

  6. N-WAY DECISIONS • More than 2 alternates? • Nested else statements (else if) • switch – case (Excel CHOOSE) • Example: Random message using switch

  7. BUT IF IT’S ONLY THE DATA… • Arrays • Collection of items referenced with index • Just keep adding items! • Start with 0 • Example: Select an element from an array

  8. DATE

  9. DATE AND TIME Full date is unfriendly format • To get today’s date: var d = new Date(); • To get the time: var time = d.getHours(); • To get the day: var theDay=d.getDay(); w3schools http://www.w3schools.com/js/js_date_methods.asp

  10. WHAT DOES IT MEAN? • Objects have attributes • Chair: color, size, legs, wheels, … • Date: year, month, day, day of week, hour, … • Object.retrieve-attribute • Assign the date with built in function Date() • Extract the piece using getHours, getDays , …

  11. DATE AND TIME EXAMPLES 3 messages based on Hour Prints an appropriate message based on time of day (3 choices) 2 messages based on Day Prints an appropriate message based on day of week (2 choices)

  12. CHANGES OUTSIDE FORMS

  13. RETRIEVING THE VALUE • In JavaScript document.getElementById("name").value • What does that mean? • document: the web page • getElementById: find this id on the page • Returns an object • Value: get the value of the object

  14. WRITING TO THE PAGE • Use an id on any element • Replace the element using innerHTML • Allows us to keep the correct semantics in HTML Using innerHTML

  15. CHANGING HTML General structure: context.element.attribute Within form: formname.element.attribute form-name . input-id .value form-name . img-id .src Outside form: document.getElementById (“id - name”).attribute document.getElementById (“ id ”). innerHTML document.getElementById (“ id ”). className document.getElementById (“ id ”). src

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend