0

What’s wrong with this js code and why it’s not working in the console(I’m a beginner)

function caculateAge(birthyear){     return 2019 - birthyear; } var AgeElijah = caculateAge(2000); var AgeAaliyah = caculateAge(2001); var AgeYasmin = caculateAge(2002); console.log(AgeElijah, AgeAaliyah, AgeYasmin); function yearUntilRetirement(year, firstname){ var age = calculateAge(year); var retirement = 65 - age; if (retirement > 0){ console.log(firstname + 'retires in' + retirement + 'years'); } else {console.log(firstname + 'is already retired.'); }} yearUntilRetirement(2000, 'Elijah'); yearUntilRetirement(2001, 'Aaliyah'); yearUntilRetirement(2002, 'Yasmin');

29th Dec 2019, 5:55 AM
Ace_ Tino_
Ace_ Tino_ - avatar
2 ответов
+ 3
in addition to ipang's answer, sololearn console log function accept one single argument only. You should use console.log( a + " " + b) ; instead of console.log(a, b) ;
29th Dec 2019, 6:31 AM
Gordon
Gordon - avatar
+ 2
Your function is named `caculateAge`. But in the `yearUntilRetirement` function you are calling an undefined function `calculateAge`. See how their name differs? caculateAge calculateAge Rename your function properly and the code should work 👍
29th Dec 2019, 6:06 AM
Ipang