0
How could I give a loop in array? The code takes the current day and adds a value x
. For example, I would like when you get to Monday where the script
document.getElementById("g").innerHTML = (dias[now.getDay() + 6] + ", " + [now.getDate () + 6] + " de " + meses [now.getMonth() ]);
(it will add Monday plus 6 days), but it gives error, because there will be only 5 more days in the array. So what I wanted was for him to create a loop.
var now = new Date();
var dias = ["DOMINGO","SEGUNDA","TERÇA","QUARTA","QUINTA","SEXTA","SABADO"];
var meses = ["JAN", "FEV", "MAR", "ABR", "MAI", "JUN", "JUL", "AGO", "SET", "OUT","NOV", "DEZ"];
document.getElementById("a").innerHTML = (dias[now.getDay()] + ", " + now.getDate () + " de " + meses [now.getMonth() ]);
document.getElementById("b").innerHTML = (dias[now.getDay() + 1] + ", " + [now.getDate () + 1] + " de " + meses [now.getMonth() ]);
document.getElementById("c").innerHTML = (dias[now.getDay() + 2] + ", " + [now.getDate () + 2] + " de " + meses [now.getMonth() ]);
document.getElementById("d").innerHTML = (dias[now.getDay() + 3] + ", " + [now.getDate () + 3] + " de " + meses [now.getMonth() ]);
document.getElementById("e").innerHTML = (dias[now.getDay() + 4] + ", " + [now.getDate () + 4] + " de " + meses [now.getMonth() ]);
document.getElementById("f").innerHTML = (dias[now.getDay() + 5] + ", " + [now.getDate () + 5] + " de " + meses [now.getMonth() ]);
document.getElementById("g").innerHTML = (dias[now.getDay() + 6] + ", " + [now.getDate () + 6] + " de " + meses [now.getMonth() ]);
It wasn’t clear what you want to do, but have you thought about taking the rest of the split by 7? So, if the sum result exceeds 6, it goes back to the top of the list.
– Woss
Well that I would like to do, but how would I do that? What should I use? How should I do it? If you can help me I would really appreciate it.
– Mikeias Alaéviton
As I said, it’s not clear what you want to do. If you can [dit] the question and try to be clearer, it might be possible. Explain, for example, what the code should do and who all these elements are in the DOM;
– Woss