I need to make a given number in a div, the numbers are different for every day of the week, but at the end of the last day of the week, the number should be the one from the first day. I tried to make this script, but I only can show the day 1 number, day 2, 4 etc. doesn't change at all, what am I doing wrong?
Btw I have a few divs, and the numbers must be different for each div, so I use Content.makeNumber = function (day1, day2, day3, day4, day5, day6, day7 for it. And the number should be up even after reload, so I take date from localStorage
const Content = {};
Content.makeNumber = function (day1, day2, day3, day4, day5, day6, day7) {
let date = localStorage.getItem("date");
const week = 60*60*24*7;
if (date === null) {
const now = Date.now();
localStorage.setItem('date', 'now');
localStorage.setItem('dateWeekEnd', 'now' + 'week');
return day1;
} else {
}
date = Number(localStorage.getItem('date'));
const dateNow = Number(localStorage.getItem('dateWeekEnd'));
const dateCount = (dateNow - date) / week;
let res
switch (dateCount) {
case 1:
res = day1;
break;
case 2:
res = day2;
break;
case 3:
res = day3;
break;
case 4:
res = day4;
break;
case 5:
res = day5;
break;
case 6:
res = day6;
break;
case 7:
res = day7;
break;
default:
res = day1;
break;
}
return res;
};
export default Content;