+ 1

The date object result gives Friday and undefined

Friday and undefined is the result. Why is it not Friday alone? function main() { var year = parseInt(readLine(), 10); var month = parseInt(readLine(), 10); var day = parseInt(readLine(), 10); var daysName = this.day; 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); //complete the function var i = d.getDay(); var daysName = names[i]; console.log(daysName); }

17th Apr 2021, 1:58 PM
Lee 4 Code
Lee 4 Code - avatar
2 Answers
+ 4
function getWeekDay isn't returning anything yet you are using console.log on it. Simply call the function otherwise it will print undefined if no value is returned by the function.
17th Apr 2021, 2:04 PM
Abhay
Abhay - avatar
+ 2
Thank you Abhay!
17th Apr 2021, 2:10 PM
Lee 4 Code
Lee 4 Code - avatar