1 / 7

Challenge Two

Challenge Two. Summary. Copy challenge 1 as challenge 2 Open index Open controller.js Change txtName to txtBirthday Given JavaScript to calculate seconds alive. Create Challenge 2. Select your “challenge 1” folder Press control and C at the same time to copy the folder

Download Presentation

Challenge Two

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. Challenge Two

  2. Summary • Copy challenge 1 as challenge 2 • Open index • Open controller.js • Change txtName to txtBirthday • Given JavaScript to calculate seconds alive

  3. Create Challenge 2 • Select your “challenge 1” folder • Press control and C at the same time to copy the folder • Press control V to then paste the folder • Rename folder as Challenge 2

  4. Open Challenge 2 • Open up DreamWeaver • Drag the index.html page onto any dark grey area in DreamWeaver to open • Open up the “JS” folder • Drag the controller.js into DreamWeaver to open

  5. Change HTML • Make sure you are looking at index.html • Change the title, H1 to Challenge two • Change the <p> text to: • “Please put in your d.o.b in the format dd/mm/yyyy to calculate your age in seconds!” • Change the text box’s id to “txtBirthday” • Save your index.html

  6. Change the JavaScript • Paste the following into the calculate function: varbirthdayText = document.getElementById('txtBirthday').value; varbirthdayTextParts = birthdayText.split("/"); varbirthdayDay = birthdayTextParts[0]; varbirthdayMonth = birthdayTextParts[1]; varbirthdayYear = birthdayTextParts[2]; var today = new Date(); today.setMonth(today.getMonth() +1); var birthday = new Date(birthdayYear, birthdayMonth, birthdayDay,0 ,0 ,0 ,0); vardif = today - birthday; var seconds = Math.round(dif / 1000); alert(“you are “ + seconds + “ seconds old”);

  7. Run index • Make sure you’ve saved the JavaScript • Back in the index page press the globe icon and run in Internet explorer. • Type in your birthday • How many seconds old are you?

More Related