javascript - Failure to calculate the total monthly payment for a car loan. What's going wrong? -


updated code. calculate() still not working. monthly payment amount not being passed "total" id box. see underlying problem here? syntax seems correct, believe there may problem specification of each variable applied in code.

i having problems getting function calculate() pass correct result in "total." possible solutions? action of clicking calculate button should display total, displaying nothing @ all, if button not activate calculate function @ all.

<!doctype html> <html> <head>     <script type="text/javascript"> function calculate() { var p = document.getelementbyid("price").value; var d = document.getelementbyid("dp").value; var r = document.getelementbyid("r").value; var n = document.getelementbyid("n").value; var = (r / 1200); var n = (n * 12); var m = ((p - d) * * math.pow(1 + i,n)) / (math.pow(1 + i,n) - 1); var result = document.getelementbyid('total');     result.value = m;} </script> </head> <div align="center">     <hr>     <form name id="main">         <input type="number" id="price" placeholder="price of car"/>         <br>         <br>         <input type="number" id="dp" placeholder="down payment"/>         <br>         <br>         <input type="number" id="r" placeholder="annual % rate"/>         <br>         <br>         <input type="number" id="n" placeholder="# of years loaned"/>         <br>         <br>         <input type="button" id="calculate" value="calculate" onclick="javascript:calculate();"/>         <br>         <br>         <input type="number" id="total" placeholder="total cost..." readonly=""/>         <br>         <br>         <input type="reset" value="reset">     </form>     <hr> </div> </html> 

use math.pow() function instead. ^ operator not mathematical power operations (see https://developer.mozilla.org/en-us/docs/web/javascript/reference/operators/bitwise_operators#bitwise_xor , https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/math/pow).

also, it's result.value = m, not other way around :)

also 2: r , m seem undefined me, have initialize variables something, did p , d.

also 3: use chrome dev tools or that. make life easier. remember, javascript doesn't mean "no ide" :d


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -