Assessment wanted for conditionals 4

Hello everyone. I’m looking for an assessment for conditionals 4. My code is working but i would love some feedback that lets me know if my solution is good/correct!

Link to the exercise

my code

if (machineActive === true) {
machineResult = ‘your machine is on!’;
} else (machineResult = ‘your machine is off!’);

(machineActive === true && pwd === ‘cheese’) ? pwdResult = ‘you have logged in successfully’: pwdResult = ‘you failed to login successfully’;

Hi there @Hassan_Garshasb!

I have tested your code and it seems to work fine, well done!

It is roughly the same as our code, just structured a bit differently. This is what we did: https://github.com/mdn/learning-area/blob/master/javascript/building-blocks/tasks/conditionals/marking.md#task-4

1 Like

Great, thanks for the feedback! I have a question regarding general programming, how long do you like to spend attempting a problem before looking at a solution?

I sometimes spend a few hours struggling with it and eventually get it, other times I spend 20 - 30 minutes and if I can’t get it, I peek at the solution and try to understand it. I’m worried by doing this I’ll be inhibiting creativity and not developing my problem solving skills. Any suggestions/advice?

Thanks in advance!

@Hassan_Garshasb this is a really interesting question. I think the best approach differs, for different people, but there is still general advice I can give.

When I’m trying to solve a problem in code, if it is something simple and small I just do it. If it is something larger, with multiple parts, I tend to get out a pencil and paper, and draw myself a box diagram/flowchart showing the different bits of functionality that need to work together, and draw arrows to show which box’s outputs become inputs for other boxes. Sort of like this, but for individual functions in a program.

Then I look at implementing each part of the code in turn. If I can’t think of how to do it, I immediately start searching the web for useful pages on MDN, stack overflow, etc., for hints or solutions. There is not point torturing yourself for an hour before trying to find out the answer - just go for it. Being able to effectively search for the information you need is a vital skill for good programmers - no one is expected to just remeber it all!

Of course, in your case, this would mean searching around the web for hints and tips, not just going straight to the solution.

If you still can’t get it after doing that, then maybe then is a good time to look at the solution.

2 Likes

Hi, can anyone assess my code to see if its correct. It’s abit different, it seems to work fine.

https://codepen.io/vddroid/pen/PoqgGLB

Hi there @vddroid! Welcome to the community, and thanks for sending in your code!

This works yeah; basically you’ve got it right. My only concern is that it seems a bit strange to mix together the test for the password being correct with the machine state.

In our answer we keep the machine test and the password test completely separate, so the code is a bit more logical and easy to read.

Thank you for the feedback. I will keep this in mind for the future.