I have searched extensively, but I couldn't find anyone discussing this particular topic.
Between April 1st and August 1st, a price starting at $900 gradually increases to $1500. This amounts to approximately $5 per day, with the following formula:
ROUND(1500 - (600 * ((DEADLINE - TODAY) / (DEADLINE - START)))
My challenge is converting this formula into JavaScript and HTML so that I can display it in a sentence like "Today you'll have to pay $920."
This is my progress so far, but I am struggling to reset today's date for accurate calculations:
<div id="foo"></div>
<script type="text/javascript">
function getDayDiff(a, b) {
return (a - b) / 8.64e7;
}
function getPayAmount(DEADLINE, TODAY, START) {
return Math.round(1500 - (600 * getDayDiff(DEADLINE, TODAY) / getDayDiff(DEADLINE, START)));
}
document.getElementById("foo").innerHTML = "Today you'll have to pay $" + getPayAmount(new Date(2021, 08, 1), new Date(), new Date(2021, 4, 1));
</script>