Search code examples
javascriptcodepen

I am missing something


I've looked this code over and over.. I typed it as I was learning from lesson material, and have checked and checked over and over again. the code works for the instructor, but not me. Is it my mistake or is it a problem for the platform I am using? It not working may seems trivial comparing to needing to understand what is being taught, but I still would like to understand all that I can. thank you. https://codepen.io/Slimmwillis/pen/EQWpGP?editors=1111

function yearsUntilRetirement(name, year) {
  var age = calculateAge(year);
  var retirement = 65 - age;
  if (retirement >= 0) {
    console.log(name + ' retires in ' + retirement + ' years.');
  } else {
    console.log(name + ' is already retired.');
  }
}
yearsUntilRetirment('John', 1990);

Solution

  • you need to be very careful while typing. You're not calling the right function so nothing happens.

    function yearsUntilRetirement(name, year) {
      var age = calculateAge(year);
      console.log('hello');
      var retirement = 65 - age;
      if (retirement >= 0) {
        console.log(name + " retires in " + retirement + " years.");
      } else {
        console.log(name + " is already retired.");
      }
    }
    yearsUntilRetirment("John", 1990);
    

    Check the yearsUntilRetirment("John", 1990); ! the name doesn't match the function.