The live out put shows ‘machine on’ in one line and ‘log in successful’ in the second line, if the machine is on. However, when the machineResult is ‘machine is off’ the second line still appears displaying ‘log in unsuccessful’
let machineActive = true;
let pwd = 'cheese';
let machineResult;
let pwdResult;
// Add your code here
if (machineActive==true) {machineResult='machine is on';}
else {machineResult='machine is off';}
(machineResult=='machine is on' && pwd=='cheese')? pwdResult='log in successful': pwdResult='log in not successful';
first i recommend that you use === for comparison why? cause it check the value and the type both must match to get true but == only check value
so for example let x = 5 if we check x===“5” it will be false but x==“5” is true
which could lead to many bug later
you code say the if will check if machine is on or off
then after that it check if machine is on and pwd is chesse then it set pwd to success but if the machine was off or pwd not cheese or even both it will set pwd result to fail
you can change the order of the code and do little modify
(machineResult=='machine is on' && pwd=='cheese')? pwdResult='log in successful': pwdResult='log in not successful';
if (machineActive===true) {machineResult='machine is on';}
else {machineResult='machine is off';
pwdResult=''}
or check this tricky tranery statment
(machineActive===true) ? ((machineResult='machine is on')=== 'machine is on' && pwd === 'cheese') ? pwdResult='log in successful' : pwdResult='log in not successful' : machineResult='machine is off';
You are a genius!! However, for your first code I noticed there was an issue but managed to sort it.
|| instead && works the live output perfectly. I think its because by the time the computer reads machineResult for the first time, it takes into account that it is uninitialized and && stops evaluating when it reaches its first falsy value.
And for the second code, you didn’t need to add the extra ==='machine is on' line as it works fine without…
I’ve learnt so much breaking down your solutions! Thank you
You’re telling me! I hated the 3rd test… i even wound up angry and leaving other forums when they gave wrong advice without actually attempting the test itself lol…
I am glad that i managed to truly learn at a deeper level tho…
And that is awesome that it worked. Def gonna use that way if i ever come across needing to code that way.