48 righe
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			48 righe
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
//Licensed under the Apache License 2.0. See license file for information.
 | 
						|
// Ardon Compound Interest Calculator v1.0.0 Alpha
 | 
						|
// Written by Josh Mudge
 | 
						|
// Ad Mejorem Dei Glorium
 | 
						|
 | 
						|
function calculate() {
 | 
						|
  var numReg = /^\d+$/;
 | 
						|
  var final = 0;
 | 
						|
  var i = 0;
 | 
						|
 | 
						|
  // Get user input
 | 
						|
 | 
						|
  var amount = document.getElementById("amount").value;
 | 
						|
  var time = document.getElementById("time").value;
 | 
						|
  var rate = document.getElementById("rate").value;
 | 
						|
  var contribution = document.getElementById("contribution").value;
 | 
						|
 | 
						|
  if (amount.match(numReg))
 | 
						|
  {
 | 
						|
    //Do nothing.
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    //Tells them to enter only numbers.
 | 
						|
 | 
						|
    alert("Please enter only numbers in this field.");
 | 
						|
  }
 | 
						|
 | 
						|
  var rate = rate * 0.01
 | 
						|
  console.log(rate)
 | 
						|
  var interest = amount * rate
 | 
						|
  console.log(interest)
 | 
						|
  var final = amount;
 | 
						|
 | 
						|
  for (i = 0; i < time; i++) {
 | 
						|
      var final = +final + (+final * +rate)
 | 
						|
      console.log(final)
 | 
						|
}
 | 
						|
console.log("Test")
 | 
						|
console.log(final)
 | 
						|
 | 
						|
  //Show result
 | 
						|
  alert("You final investment amount is $" + final);
 | 
						|
  document.getElementById("interest").innerHTML = "Your final investment amount is $" + final;
 | 
						|
 | 
						|
}
 |