javascript - Why doesn't my function to calculate monthly car payments work? -


i creating small web app users can enter ideal car price , find out how (on average) monthly payment be.

half of function works , able tophalf variable calculation not rest of equation.

formula used

http://teachertech.rice.edu/participants/bchristo/lessons/carpaymt.html

html used

<input type="input" placeholder="carprice" id="rprice">     <input type="input" placeholder="deposit" id="deposit">     <input type="input" placeholder="interest rate" id="irate">     <input type="input" placeholder="loan term" id="tmonth">     <a onclick="findpayment()">calculate</a> 

javascript used

function findpayment() {  /* add user's unique input fields here */  var regprice = document.getelementbyid("rprice").value; deposit = document.getelementbyid("deposit").value; rate = document.getelementbyid("irate").value; mth = document.getelementbyid("tmonth").value;  /* find updated price including user's deposit */  uptprice = regprice - deposit;  /* formula calculate here */  tophalf = uptprice * ( rate / mth ); bottomhalf = 1 - math.pow( 1 + rate / 12, -mth) custom = tophalf / bottomhalf;  /* send monthly payment console can check */  console.log(custom);  }; 

thank help!

you need parseint or parsefloat values of actual inputs manipulate them numbers.

currently should display nan or of sort, nan stands not number, shows because trying use mathematical operators on strings.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -