How to solve task 127 without using any "if " statement.
How to solve task 127
Hints:
- You can return the boolean value without an
if
using thereturn
statement. - You can use the operators
&&
and||
to combine boolean values.
Oh boy! This one gave me a headache were you successful with the explanation @juju?
alxjspalma help me with this Coderslang_Master
- Edited
A quick note about this including my solution, Heroes. This is one of those issues where I originally tried a more complex set of calculations outside of an if statement. Truth be told, this ended up being a lesson in simplicity. Using the return statement, this ended up being my HELPER.JS
export const oneWillDo = (x, y, z) => {
return x + y + z >= 1;
}
Basically, this uses the mathematical equivalent of true and false (0 and 1) and say that any combination of those values would create a mathematical construct that was 1 or more for all truthy statements. I would say I'm about 85% sure of it, but the autograder said it was good to go.
TTFN,
GM
MisterManley that's a clever solution
a more straightforward combo would be to use the ||
operator instead of +
As a || b
returns true if either a
OR b
are true
export const oneWillDo = (x, y, z) => {
return x | | y | | z ;
}
- Edited
This solution worked for me
export const oneWillDo = (x, y, z) => {
return x | | y | | z === true;
};
yacine919
It worked but I don't understand.
Oluwatomisin_Joy you should never copy someone else's code. If you don't understand it's ok, but you should crack the problem on your own.
Ask questions, and come up with ideas, but don't look for shortcuts.
- Edited
Oluwatomisin_Joy this solution worked for me
export const oneWillDo = (x, y, z) => {
return x or y or z == true;
}
If I'm right this solution is checking if anyone of x, y and z is true then it will return true otherwise it will give false. For deep understanding please look at the values given in solution.js file . I have written "or" instead of in the solution because it was not showing . So, please don't be confused.
- Edited
Coderslang_Master can u explain i cant understand x or y or z
Jaybamaniya I don't understand your question, could you be more specific?