Trying to calculate daily earning if $ is doubled each day- starting at one cent. I have most of it going except on day 1 I get 2 cents where it should be 1 cent.
<script>
var money = 1;
for (var i = 1; i < 31; i++) {
money = money * 2;
total = money /100;
document.writeln("<p>After day " + i + " you will have " + money + " cents.</p>");
}
document.writeln("<p>In thirty days you will have earned $" + total + ".</p>");
</script>
var money = 1;
var total = 0;
for (var i = 1; i < 31; i++) {
// as you've already set the money for the 1st day, start the calculating loop from the 2nd day
if(i = 1){
total = money /100;
document.writeln("<p>After day " + i + " you will have " + money + " cents.</p>");
}else{
money = money * 2;
total = money /100;
document.writeln("<p>After day " + i + " you will have " + money + " cents.</p>");
}
}
document.writeln("<p>In thirty days you will have earned $" + total + ".</p>");
as you've already set the money for the 1st day, start the calculating loop from the 2nd day