Javascript problem

Hey guys, please help me out here.

Write a function called sameWeekday that takes in two dates and check if both dates have the same weekday.

For example if both dates are on a Tueday the function should return true.

My code:
function sameWeekday(date1, date2) {
const weekdays = [“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”];
const weekday1 = weekdays[date1.getDate()];
const weekday2 = weekdays[date2.getDate()];
return weekday1 === weekday2;
}

I’m getting an error.

TypeError: date1.getDate is not a sameWeekday function tion
TypeError: date1.getDate is not a function at sameWeekday (eval at…

assert.equal(sameWeekday(‘2016-11-19’, ‘2016-11-26’), true);
assert.equal(sameWeekday(‘2016-11-19’, ‘2016-11-28’), false);

The day of the month

Okay, you make valid points. So where should I change?

The code, what should I change to make it work?

Alright, thank you. I’ll try that.

One more thing, if you can, please delete this topic/thread.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.