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 }
1 Odpowiedź
+ 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() ];
}