0

What makes it suddenly turn to text?

So below you see the exercise has been completed but I don't get the exact proces behind it. Why does putting the d.getDay in those arrays at the bottom suddenly make it turn into the right text? function main() { var year = parseInt(readLine(), 10); var month = parseInt(readLine(), 10); var day = parseInt(readLine(), 10); console.log(getWeekDay(year, month, day)); } function getWeekDay(year, month, day) { var names = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var d = new Date(year, month, day); return names[d.getDay()]; }

21st Feb 2021, 3:18 AM
SuperKitsune94
SuperKitsune94 - avatar
1 Resposta
0
var d = new Date(year, month, day); creates a date object with the current date. using d you can access the methods of Date(). to do so you use the object.method() form. d in this case is the object. d.getDay() returns the current day as an int from 0 to 6. Sunday = 0, Monday = 1,..., Saturday =6. names[d.getDay()] is equivalent to names[0]. as i'm writing this on Sunday. on Monday it will be equivalent to names[1]. and so on.
21st Feb 2021, 8:28 AM
Bahhaⵣ
Bahhaⵣ - avatar