If we have an alien manager as the admin, then the variable values are:
isAdmin=true;isManager=true;isAlien=true;
The ternary version returns the correct result, "All Allowed", because our alien manager is an admin.
constresult=isAdmin?"All Allowed":isManager?"Some Allowed":isAlien?"Run":"Not Allowed";// result == "All Allowed"
However, the offered serial if statements return the wrong result value, "Run", treating our manager as a low permissioned alien instead of a high permissioned admin.
letresult="Not Allowed";if(isAdmin){result="All Allowed";}// result == "All Allowed"if(isManager){result="Some Allowed";}// oops, the admin is also a manager, so now result == "Some Allowed"if(isAlien){result="Run";}// oops again, the admin manager is also an alien, so now result == "Run"
If the ternary is going to be converted into if statements, then they should be if-else statements.
letresult="Not Allowed";if(isAdmin){result="All Allowed";}elseif(isManager){result="Some Allowed";}elseif(isAlien){result="Run";}// result == "All Allowed"
Now our alien manager is rightly given their admin level permissions.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think you’re wrong.
No, pjotre86 is completely right.
If we have an alien manager as the admin, then the variable values are:
The ternary version returns the correct result, "All Allowed", because our alien manager is an admin.
However, the offered serial if statements return the wrong result value, "Run", treating our manager as a low permissioned alien instead of a high permissioned admin.
If the ternary is going to be converted into if statements, then they should be if-else statements.
Now our alien manager is rightly given their admin level permissions.