Reputation:
how can I console log a day of the week that is now and after it the days left for the week to end ?
example
today is Monday
mon tue wed thu fir sat sun
today is fri
fir sat sun I want it to show the day that is now and the rest of the week. to end
Upvotes: 0
Views: 313
Reputation: 835
What I did is created an array of the days of the week in order and then looped through that to add the day you are looking for and all days after that to a new array.
const daysOfWeek = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
let currentDay = prompt("Enter day of week:");
while (!daysOfWeek.includes(currentDay)) {
currentDay = prompt("Invalid day. Enter day of week:").toLowerCase();
}
let currentDayPassed = false;
const daysLeft = [];
for (let i = 0; i < daysOfWeek.length; i++) {
if (daysOfWeek[i] === currentDay) {
currentDayPassed = true;
}
if (currentDayPassed) {
daysLeft.push(daysOfWeek[i]);
}
}
console.log(daysLeft);
Upvotes: 0