Write a javascript function named calculateTradeIn than can do the following cal
ID: 658227 • Letter: W
Question
Write a javascript function named calculateTradeIn than can do the following calculation:
Subtract 15% depreciation of a declining balance for each year based on the difference between the model year and the current year (for example, a 2010 car traded in 2015 would be five years old.) A one year old car is worth 85% of the current trade-in value, a two year old car is worth 72.25%, etc. A simple mathematical calculation can be used to apply the depreciation percentage to the current trade-in value. (HINT: Use Math.pow).
Explanation / Answer
function calculateTradeIn (model_year,curr_tradein_val)
{
var year_diff = cur_year - model_year;
var tot_percent=100;
var dep_percent=15;
if (year_diff > 0)
{
for(int i=0; i < year_diff ; i ++)
{
tot_percent = tot_percent - (dep_percent * tot_percent * 0.01);
}
}
var dep_value = tot_percent * 0.01 * curr_tradein_val;
return dep_value;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.