javascript - Why don't my numbers add correctly -


here's code i'm running

function howoldareyou(day,month,year) { var age; age = (day) + (2015-year) + (month*12); return age };   document.write(howoldareyou(parsefloat(prompt("yo day"))),(parsefloat(prompt("yo month"))),(parsefloat(prompt("yo year")))); 

i know got age formula wrong, should added number back, , instead i'll this: if put "1" in first prompt, "2" in second, , "3" in third, i'll on document "nan23". feel it's small parenthesis problem, can't figure out, , appreciated.

because howoldareyou function being called after first prompt, you're passing, example: howoldareyou(1, undefined, undefined)

design choices aside, can make you're doing work this:

function howoldareyou(day,month,year) {     var age;     age = (day) + (2015-year) + (month*12);     return age };  var day = parsefloat(prompt("yo day")); var month = parsefloat(prompt("yo month")); var year = parsefloat(prompt("yo year"));  document.write(howoldareyou(day, month, year)); 

or, keep how had it, correct format be:

document.write(     howoldareyou(parsefloat(prompt("yo day")),                   parsefloat(prompt("yo month")),                   parsefloat(prompt("yo year")))); 

Comments