70 likes | 296 Views
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
E N D
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 • Press control V to then paste the folder • Rename folder as Challenge 2
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
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
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”);
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?