Download presentation
Presentation is loading. Please wait.
1
JavaScript Arrays Date
2
Arrays
3
Producing different results
We have looked at how to compute different numeric values Computation Random How do we create different strings? Can do it from user input But want to translate a number to a string Examples: Random facts Convert month or day number to string
4
Arrays Collection of related information
Referenced with index Easy way to choose between items var array = [ “A", "B", “F", "G" ]; Just keep adding items! array[index] Start with 0 Example: Date returns number, you return that month
5
Create your first array
Change a number to text Create a JavaScript function called spellIt Takes in a number from 0 to 9 Returns a string with the number name Call it with a button press, passing the user input
6
Date
7
Date() Returns a collection of information
Year, month, day, hours, minutes, seconds, milliseconds
8
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
9
What does day return? Number 0 to 6
Want to convert to Sunday, Monday, … var DayOfWeek = [“Sun”, “Mon”, “Tues”, “Wed”, “Thurs”, “Fri”, “Sat”];
10
Display the current month
Create a JavaScript function called monthName To be in the same file as spellIt No parameters needed Returns a string with this month’s name
11
Extend spellIt Accept a number 20-29 and spell it out Subtract 20
twenty, twenty-one, twenty-two, …, twenty-nine Subtract 20 Will need to change the array to include - What should the 0 array value be?
12
HTML Page It should print the date of your last major assignment
User enters a number between 20 and 29 Button press returns the month and date spelled out Example: Enter 27 Returns April twenty-seven
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.