Pck48
1
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.
Pck48
3
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);
Pck48
7
Okay, you make valid points. So where should I change?
Pck48
9
The code, what should I change to make it work?
Pck48
11
Alright, thank you. I’ll try that.
Pck48
12
One more thing, if you can, please delete this topic/thread.
system
Closed
14
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.