These are assignments:
This solution:
These are assignments:
This solution:
Hi Svitcher and welcome back!
All four tasks work as expected. Congratulations!
Here are some remarks regarding readability/simplicity:
if (score < 0 || score > 100) {
response = 'This is not possible, an error has occurred.';
} else if ...
if (!machineActive)
instead of if ( machineActive === false )
pwdResult
in front:pwdResult = pwd === 'cheese' ? 'Login successful.' : 'Password incorrect; login failed.'
I hope my feedback is helpful. Please just ask if you have more questions or tasks to be assessed
Michael
Hello! Thank you so much for your advice. They are very important to me. I tried this code in the 4th task:
'pwdResult = pwd === ‘cheese’ ? ‘Login successful.’ : ‘Password incorrect; login failed.’
But the program gives the result: true and doesn’t assign the right value to the pwdResult variable.
Nataliia
Hmm… I just copied my code into your codepen (replacing your own line) and it worked It looks like this:
if (machineActive) {
machineResult = 'The machine is switched on';
pwdResult = pwd === 'cheese' ? 'Login successful.' : 'Password incorrect; login failed.'
} else {
machineResult = 'The machine is switched off';
}
This is a new link: Conditionals 4 - JSFiddle - Code Playground
My expression was in brackets. Yes, JS has a strange syntax.
Ahhhhh… now I see
(pwdResult = pwd === 'cheese') ? 'str1': 'str2' /* pwd === 'cheese' gets evaluated first */
(pwdResult = true) ? 'str1': 'str2' /* true gets assigned to pwdResult */
true ? 'str1': 'str2' /* evaluates to 'str1', but it doesn't get assigned anywhere */
It’s sometimes tricky to know what gets evaluated/assigned first. This topic is called “operator precedence”. If you are brave enough MDN has an article about it: MDN | Operator Precedence. Especially the table at the end is pretty scary
I got it, thank you.