0

Why does my code output the number of the names parameter instead the weekday name. Date object!

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); this.name = names; return getWeekDay = d.getDay([this.name]) //complete the functio }

26th Dec 2020, 5:46 AM
Emmanuel Riano
Emmanuel Riano - avatar
1 Réponse
+ 3
function getWeekDay( year, month, day ) { var names = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]; var d = new Date( year, month - 1, day ); return names[ d.getDay() ]; }
26th Dec 2020, 9:57 AM
Ipang