i need help with a javascript code that's calculate the profit of investment with a rate of 4% daily for a period of 30 days : Screenshot 1
var minimumAmount = 5;
function DoCalculate() {
var temp1 = $("#txtAmount").val(),
rate = 0.0;
if (!$("#txtAmount").val()) temp1 = 0;
var initial = parseFloat(temp1);
if (initial < minimumAmount) rate = 0;
else rate = 0.04;
var totalReturn = parseFloat(initial * rate * 30);
if (initial < minimumAmount) {
$("#lblDailyProfit").html("0.00");
$("#lblHourlyProfit").html("0.00");
$("#lblTotalProfit").html("0.00");
$("#lblTotalReturn").html("0.00");
} else {
$("#lblDailyProfit").html(parseFloat(initial * rate * 24).toFixed(2));
$("#lblHourlyProfit").html(parseFloat(initial * rate).toFixed(2));
$("#lblTotalReturn").html(totalReturn.toFixed(2));
$("#lblTotalProfit").html((totalReturn - initial).toFixed(2));
}
}
$(function() {
DoCalculate();
$("#txtAmount").blur(function() {
if (parseFloat($(this).val()) < minimumAmount) $("#txtAmount").val(minimumAmount);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
I want to add multiple rates like :
if ( initial >= 3000 && initial <= 4900 ) rate = 0.02;
if ( initial >= 5000 && initial <= 49999 ) rate = 0.04;
if ( initial >= 50000 && initial <= 49999 ) rate = 0.09;
I've tried many times but with not results, I will be happy if someone helps me; Thanks in advance.