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

Top comments (0)

Why You Need to Study Javascript Fundamentals

The harsh reality for JS Developers: If you don't study the fundamentals, you'll be just another β€œCoder”. Top learnings on how to get to the mid/senior level faster as a JavaScript developer by Dragos Nedelcu.