JavaScript Fundamentals Code Challenges

Hello, I am having an issue with using return in the code challenge. If I console.log() the function, the results are as they should be; the math is calculated properly and the strings are showing up perfectly but the function only works when its logged to the console and not just on its own. If the code is working properly when it is logged, what am I missing so that it works when I call the function alone?

Here is the link to the exercise: https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/code-challenge-javascript-fundamentals/lessons/javascript-fundamentals-code-challenge/exercises/how-old

Here is a link and image to my code: https://gist.github.com/2a28c8dd42d98a7a38bdd52f4d17a373

Welcome, @juantourage,

It’s not unlikely that a function will be expected to compute some value and then send the result back to its caller. Sometimes that result will be needed in future computation and needs to be accessible at that time. That’s why we seldom log results in the functions we use to compute them. We want those values to passed along, as opposed to undefined.

Thanks for responding, I get how it’s supposed to work i’m looking to understand what i’m missing so that it works without needing to console.log() it. If you see my code below, you’ll see i am returning each string and arguement using string interpolation. I believe my code is correct as it is doing its job but i need it to execute independently. Please advise,

let howOld = (age, year) => { let currentYear = 2019; let yearDifference = year - currentYear; let newAge = age + yearDifference; if(newAge > age) { return 'You will be ' + newAge + ' in the year ' + year; } else if(newAge < 0) { return 'The year ' + year + ' was ' + yearDifference + ' years before you were born'; }else{ return 'You were ' + newAge + ' in the year ' + year; } }