I have a task that requires me to use setInterval function 5 times every 15 minutes, totaling one hour of work. Each value retrieved needs to be displayed in an HTML table.
Below is the table:
For example, if it is 7:58 p.m., the script starts running
At 08:00, the first value is 5
At 08:15, the first value is 3
At 08:30, the first value is 2
At 08:45, the first value is 1
I currently do not have any issues, my problem is explained below
At 09:00, the first value is 6
Please refer to the image below
The value 6
is displayed in the first column instead of the last. :S
Why does the timer reset to zero? Shouldn't it add another 15 minutes normally?
The desired result is shown in this image
let atomRunTimers = setInterval(() => {
let minutes = new Date().getMinutes();
if (minutes === 0) {
let val1 = parseFloat(atomStockObject.p).toFixed(3);
let price = parseFloat(atomStockObject.p).toFixed(3);
atomStockPriceElement1.innerText = price;
atomStockPriceElement1.style.color =
!atomLastPrice || atomLastPrice === price
? 'black'
: price > atomLastPrice
? '#AAFF00'
: 'red';
atomLastPrice = price;
atomStockObject = null;
}
if (minutes === 15) {
let val2 = parseFloat(atomStockObject.p).toFixed(3);
let price = parseFloat(atomStockObject.p).toFixed(3);
atomStockPriceElement2.innerText = price;
atomStockPriceElement2.style.color =
!atomLastPrice || atomLastPrice === price
? 'black'
: price > atomLastPrice
? '#AAFF00'
: 'red';
atomLastPrice = price;
atomStockObject = null;
}
if (minutes === 30) {
let val3 = parseFloat(atomStockObject.p).toFixed(3);
let price = parseFloat(atomStockObject.p).toFixed(3);
atomStockPriceElement3.innerText = price;
atomStockPriceElement3.style.color =
!atomLastPrice || atomLastPrice === price
? 'black'
: price > atomLastPrice
? '#AAFF00'
: 'red';
atomLastPrice = price;
atomStockObject = null;
}
if (minutes === 45) {
let val4 = parseFloat(atomStockObject.p).toFixed(3);
let price = parseFloat(atomStockObject.p).toFixed(3);
atomStockPriceElement4.innerText = price;
atomStockPriceElement4.style.color =
!atomLastPrice || atomLastPrice === price
? 'black'
: price > atomLastPrice
? '#AAFF00'
: 'red';
atomLastPrice = price;
atomStockObject = null;
}
if (minutes === 60) {
let val5 = parseFloat(atomStockObject.p).toFixed(3);
let price = parseFloat(atomStockObject.p).toFixed(3);
atomStockPriceElement5.innerText = price;
atomStockPriceElement5.style.color =
!atomLastPrice || atomLastPrice === price
? 'black'
: price > atomLastPrice
? '#AAFF00'
: 'red';
atomLastPrice = price;
atomStockObject = null;
}
}, 60000);
I appreciate any assistance provided as I am eager to resolve this issue and gain a better understanding.