DEV Community

Margaret W.N
Margaret W.N

Posted on

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

Latest comments (0)