LF codereview on my simon game proj

Hi guys.

I’d be really grateful if someone could make some time to review my code – not the design, but what’s inside the js: I kind of feel that my code is excessive and does not look cool enough. Especially I’m worrying about a bunch of nested if-else statements in $('.quarter').click(function....) Or the #checkbox click func… Can it be done in more of a gracious way?

What about lack of comments? I’ve read recently that you shouldn’t comment on what’s happening in the code, instead you comment on what a function does, what it’s returning; also, why it looks the way it looks. I’m confused cause I do not feel the difference between these statements, hence I can not differ a bad commentary from a good. So I’m looking for a comments on my commenting style also.

Here’s my work: http://codepen.io/lfg_/pen/WxyEaq?editors=0010#0

Thank you.

Your code doesn’t look bad. These sorts of games have all sorts of branches. You could probably find a better way if you sat and thought about it for a while, but remember that time is a precious resource. As far as comments, I don’t think your code needs them. You named your variables and functions well enough that I can tell what’s going on just by reading the code. It’s “self-documenting”, which is much better than writing comments.

The one thing I would change is to make sure you’re using the Babel preprocessor in CodePen if you want to write ES6 code. Some browsers still aren’t up to the latest standards and the game won’t work otherwise. You can find preprocessor settings in the same section you’d add JavaScript libraries.

Thank you for your reply. I added Babel preproc, totally forgot about it.

I agree, your code doesn’t look terrible, though I don’t think it needs blank space around every line. Whenever your code starts to feel unmanageable, breaking it out into more functions almost always helps. When your functions have good names, that makes your code even more self-documenting.

Hi, thanks. yeah I noticed others do not space lines out. I will drop it out as soon as I join a team, I suppose; like it this way though, it feels very comfortable for my eyes, and more manageable.

started to explore functional programming concepts, thanks to you. cheers.

If the extra spacing makes it easier to work with your own code, by all means keep it. As code gets higher-level, with more functions and declarations than explicit loops or low-level data munging, you’ll probably find naming conventions become more important and formatting less so.

My rule of thumb is that while a single function should usually fit on less than a page, it’s more important that it fits comfortably in your head.