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.

What error are you getting and how are you calling the function?

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);

What do you think the getDate() method returns?

The day of the month

So how does the day of the month help you determine if a date is a specific day of the week? Also, the arguments to your sameWeekday function are just strings and not dates, so you can not use the getDate method on strings.

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

Where should you change what?

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

You will need write your own code. I would suggest converting the strings into dates using the applicable JavaScript method. Then I would use the date method that gets the day of the week of a date for each date. Finally, I would return the comparison of those days of week.

Alright, thank you. I’ll try that.

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

Why would we delete it? You got your help and it could help someone else.