Hi guys ! i have an issue with the truthyOrFalsy function, can you take a look at the task via the link. normally the if statement need and else but here i don't get why it's missed!

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/code-challenge-javascript-fundamentals/lessons/javascript-fundamentals-code-challenge/exercises/truthy-or-falsy

Hello @wilfriedpiwo35277140, I can’t see your code, and I haven’t done that part of the lesson, so if you have any code, could you post it please. Otherwise, if I understand you correctly, you’re saying that it says do something like this:

function some_function(){
if (condition) {
  return "something"
}
return "somethingelse" 
}

The reason for this is the return. return ends a function, meaning that no code after that will run. This takes use of that. This code checks a condition. If it meets that condition, then return ‘something’. That then ends the function, and all code after that is not evaluated, meaning the function returns 'something'. If that condition is not met, then the other return will execute, and therefore a call to that function will result in it returning ‘somethingelse’.
I hope this helps!

1 Like

hi, this is the code .

const truthyOrFalsy = value => {
    if (value) {
        return true
    }
    return false

Hello @wilfriedpiwo35277140, as I suspected. This function does what my post (the one above) here says:

It checks a to see if a value is true. If it is, then it returns True. The code then stops, because it hit a return. Otherwise, it returns false. (see above)
Happy coding!

1 Like

okay i got it , thanks for your response.

1 Like

Hi!
I have same question.

It means, are “my code” and “answer code” both same?
Can I omit it?


(my code)

const truthyOrFalsy = value => {

if (value) {

return true

}else {

  return false

} 

}

(annswer code)

const truthyOrFalsy = value => {

if (value) {

return true

}
  return false

} 

yes your code and answer code are same … not exactly same but the result it produce is same

Thank you so much!!!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.