DEV Community

Margaret W.N
Margaret W.N

Posted on

1

Day 62: Stuck at displaying days of the week.

I'm stuck at trying to display all the days of the week. I've managed to display next day though :

const displayDate = document.querySelector('#date');
let date = today.getDate()
displayDate.textContent = `${date}th`

const tommorow = new Date(date)
const nextday = document.querySelector('#nextDay');
nextday.textContent = tommorow.toLocaleString('default', { weekday: 'long' })
Enter fullscreen mode Exit fullscreen mode

I tried to follow the same format for the preceding days but it doesn't seem to be working as expected.

I tried to cook up the following.

let days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
let day = today.getDay()
const nextday2 = document.querySelector('#nextDay2');
nextday2.textContent = days[day+2]
Enter fullscreen mode Exit fullscreen mode

I have to admit my cooking skills are not so bad. I was thinking I'd get the current day as an integer and loop through the array printing out the preceding days. But again I would have to reset the loop to execute an infinite number of times.

I have to admit this seemed so easy at first.

Day 62

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay