+ 1

Why gives "b"? Why not "a"

Why gives "b"? Why not "a" https://code.sololearn.com/WNXN3PEVOVyJ/?ref=app

8th Apr 2020, 8:34 AM
BangArray
BangArray - avatar
4 Antworten
+ 8
x && y: if x evaluates to false, no need to test further, return x (as it's false) else if x evaluates to true, the result totally depends on y, so just return y (no need to test if y evaluates to true or false, just return it) in your case, both "a" and "b" are evaluated to true, so we are in the second hypothesis. it just returns "b"!
8th Apr 2020, 8:48 AM
John Robotane
John Robotane - avatar
+ 5
Have you tried switching them or adding new strings like c d e...? Try it, I'm sure you'll find the answer.
8th Apr 2020, 8:37 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Thanks.. I got it 🤘
8th Apr 2020, 8:42 AM
BangArray
BangArray - avatar
+ 1
because both expression are considered truth,so it return the last expression
8th Apr 2020, 8:43 AM
durian
durian - avatar