If/else short Statement


#1

Hi everyone;

I am starting with javascript in the course Java Script Introduction and in the point 7… Function Declarations of Section 3 - Functions, the program does not accept the short condition within a function:
“numberOne > numberTwo ? return true : return false;”

that pretends to verify if #1 is grater then #2… If I use the “usual” if/else statement it works.

Someone could explain me why that bug occurs?
Thank u in advance.


#2

You didn’t use the ternary operator correctly:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

but even if you did, the exercise would never approve it given the exercise validation isn’t designed to handle it.


#3

Thank u!

So, basically it is missing return(…); Right?

:wink:


#4

you have return:

return true : return false

but at the wrong place, here you should only determine the value (true : false) and then what you want to do with this value (return, assign it to variable) should happen at the beginning of that line


#5

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