In my Java code, I have a method that calculates the current price, which is then utilized in my JavaScript code provided below.
function updatePrice(id, currentPrice){
var newPrice = 0;
var cPrice = currentPrice;
cPrice = cPrice * 100;
if(rate == 1){
newPrice = cPrice - 1;
}
if(rate == 2){
newPrice = cPrice - 2;
}
if(rate == 3){
newPrice = cPrice - 3;
}
document.getElementById(id).innerHTML = newPrice/100;;
return newPrice / 100;
}
var nPrice = updatePrice('reverse', currentPrice); //The new calculated price, currentPrice is the price first injected into the script
var timeinterval = setInterval(function() { nPrice = updatePrice('reverse', nPrice); }, 60000); //the nPrice as currentPrice
I aim to leverage the newPrice calculated in updatePrice on itself when executing setInterval, ensuring that every minute the newPrice decreases by 1, 2, or 3 pence accordingly;
There might be a simple solution that has escaped my notice until now.
If this explanation isn't clear, feel free to request more information.