- Function Declarations
- Calling a Function
- Parameters and Arguments
- Default Parameters
- Return
- Helper Functions
- Function Expressions
- Arrow Functions
- Concise Body Arrow Functions
If you are not familier with them please download Learn JavaScript eBook at https://codingwithbasir.com/learn-javascript
-
Create a html file with your name like john.html
-
Add current code to that file:
<!DOCTYPE html>
<html>
<body>
<script>
// your code here
</script>
</body>
</html>
- Define variables for date parts:
- year: 2019
- month: 10
- day: 9
- dayOfWeek: 2
All variables are number.
-
Declare a function named
showDayName
that get dayOfWeek (number) and log day name into the console. For example it gets1
and logSunday
,2
and logMonday
, etc. -
Declare a function named
convert2String
that convert a number to string. If number is less that 10, it puts a 0 befor it. Example:2
=>'02'
-
Declare a function named
formatDate
with 3 parameters (year
,month
,day
) and return a string with this formatyyy/mm/dd
. Note: Useconvert2String
function from previous step. -
Declare a function named
formatDateChristmas
with 3 parameters (year
,month
,day
) and return a the result offormatDate
function from pervious step. Use default parameters to show2020/01/01
if this function is called without parameters. -
Declare a function expression named
nextYear
that get a year and return next year. CallformatDate
withnextYear(year)
as first parameter andmonth
andday
for next 2 parameters. -
Declare a function named
formatDateConcised
with arrow functions that implementsformatDate
functionality with concise format.