Final Value with Appreciation
Given principal amount
principal as an input, time period in years time and appreciation percentage apprPercentage as optional inputs, write a JS function to return the final value finalValue with the given appreciation percentage and time period. The default values for time and apprPercentage are 2 and 5 respectively.
Quick Tip
The formula to calculate the final value with appreciation is,
finalValue = principal * (1 + time * appreciation / 100)
<!DOCTYPE html>
<html>
<head>
<script>
//JS function to return the final value finalValue with the given appreciation percentage and time period.
function calculateFinalValueAppreciation(principal, time = 2, appreciation = 5) {
return principal * (1 + time * appreciation / 100)
}
let principal = prompt("Enter a pricipal number: ")
let time = prompt("Enter a time: ")
let appreciation = prompt("Enter a number of appreciation: ")
let finalValue = calculateFinalValueAppreciation(principal,time,appreciation)
let finalValueDefault = calculateFinalValueAppreciation(principal)
window.onload = function() {
document.getElementById("finalValue").innerHTML ="The final value: "+finalValue;
document.getElementById("finalValueDefault").innerHTML ="The final value default: "+finalValueDefault;
};
</script>
</head>
<body>
<p id="finalValue"></p>
<p id="finalValueDefault"></p>
</body>
</html>
Comments
Leave a comment