9 votes
Accepted

Simple dice game - JavaScript MVC implementation

MVC thing is hard to be taken right. And yet it is the most popular (my guess) approach in the modern web development. There are different ways to say what MVC means in particular application. I ...
sineemore's user avatar
  • 1,785
8 votes

C++ Tree Class implementation

Some quick comments: Const correctness You really should make your code const correct. For example at least these functions could be const declared: ...
Emily L.'s user avatar
  • 16.6k
8 votes
Accepted

Selecting elements from the DOM of a page

Don't implicitly create global variables for (i = 0; uses a global i. Always declare variables before using them - in modern ...
CertainPerformance's user avatar
7 votes
Accepted

Create multiple divs inside a containing div

Descriptive names As a global function name, generate is too vague: it should tell what it's generating, something like ...
Guy Incognito's user avatar
7 votes

Showing "open" or "closed" based on the current time

The first bug is that you are misusing setInterval(). You should be passing a function, not the void result of the function, when calling ...
200_success's user avatar
6 votes
Accepted

Card-fighting game

There has always been an interesting debate between number of lines and legibility of the code. You could have less lines but not a readable or more lines and bad code. Don't focus so much on the ...
myselfmiqdad's user avatar
6 votes
Accepted

Determine closest ancestor that has a certain HTML class

Extending native prototypes is a little iffy. Not that this should cause any problems, but in principle it's best to avoid. The reason is mostly that if everyone extend native prototypes, then you're ...
Flambino's user avatar
  • 33k
6 votes
Accepted

Jasmine unit tests for a function to set attributes on an HTML element

First, your function should follow JS conventions and be camelCase, not PascalCase. The latter is for constructors, but this is ...
Flambino's user avatar
  • 33k
6 votes
Accepted

Evaluating an XPath with document.evaluate() to get an array of nodes

I don't see a method to directly turn it into an array -- Array.from doesn't work, eg. The best I could achieve was a little cleanup: ...
Jonah's user avatar
  • 4,340
6 votes
Accepted

Platformer without canvas

Review of DOM game Games coding is not easy and you have managed the fundamentals of a platformer, great work. Unfortunately your game is technically flawed in a number of areas however first I will ...
Blindman67's user avatar
  • 21.8k
6 votes
Accepted

Tic tac toe game in a web browser

Style and code Numeric styles can be set using Number. eg modalParent.style.opacity = '1'; can be ...
Blindman67's user avatar
  • 21.8k
6 votes
Accepted

Simple input class change with vanilla JS

Review The biggest critique about the Javascript I have is that collapsedInput could be declared with const because it doesn't ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes
Accepted

Refactor JavaScript nested if-else

As already suggested, you can abstract common logic to a function: ...
Miguel Alorda's user avatar
6 votes
Accepted

JavaScript front end for Odin Project book library database

There are of course many ways to structure the code, and its interesting that you opted to encapsulate Book but not Library. You ...
Dave Meehan's user avatar
5 votes

HTML5 sectioning for my design

My review will be nowhere complete. Here are some points I would change: With a doctype of <!DOCTYPE html> all browsers will recognize the document as HTML5. ...
Pyfisch's user avatar
  • 661
5 votes

Fix base64 data URI scripts function

Watch out! jQuery is full of secrets. html method is not just a simple wrapper around innerHTML property. Possible fail ...
sineemore's user avatar
  • 1,785
5 votes
Accepted

Remove the object's sibling on click

You should define one click handler that removes all siblings of the clicked element. That is, remove all children of the parent, except the target of the event itself. ...
200_success's user avatar
5 votes

C++ Tree Class implementation

Some general points: Explicit new should never be part of an interface. Use std::unique_ptr to represent a uniquely-owning ...
Reuben Thomas's user avatar
5 votes

Making thousands of DOM elements draggable with JavaScript

Here are some suggestions to improve the fluidity of your app: Use translate instead of top/left positioning According to this ...
oliverpool's user avatar
  • 1,902
5 votes
Accepted

Functional way to have two toggles that turn each other off

The logic itself is simple enough. I see that you are using ECMAScript 6, with it there are some things you could do to simplify the code and make it more robust. ...
Phrancis's user avatar
  • 20.4k
5 votes

Ensure that all `h2` tags have a `span` inserted

I would agree with discussion in comments that this should be looked at as a stop-gap solution only, as the real answer here is to change the HTML source, or better yet, the CSS styling for the ...
Mike Brant's user avatar
  • 9,608
5 votes

Evaluating an XPath with document.evaluate() to get an array of nodes

There's a slightly more concise way of filling a new array with values from a snapshot: ...
Alf Eaton's user avatar
  • 151
5 votes
Accepted

Simple Calculate Game

Nice job with the game :) As far as fixing the bug you pointed out, you want to think about what two values you are comparing to determine if the answer is correct, and also how you are comparing them....
Daniel Rearden's user avatar
5 votes
Accepted

JavaScript Random Color Generator

Looks very good. And, as far as I know, your colour generator is fair. For efficiency you don't need to generate a random number for every hex character. You are choosing among 256^3 (16 777&...
ArenaL5's user avatar
  • 76
5 votes
Accepted

Manipulating the browser history

An appropriate term for this code is spaghetti code – it's tightly intertwined with other parts of the app, so one cannot easily take out a part of it and reason about it without thinking about the ...
Rene Saarsoo's user avatar
  • 2,062
5 votes
Accepted

Showing two d3.js charts on the same page

I don't see anything wrong with the approach you're using, which is changing the variables' names and writing the code as a whole piece. The reason for that is simple: you have two fundamentally ...
Gerardo Furtado's user avatar
5 votes
Accepted

UpvoteJS, a simple voting widget in vanilla JavaScript

Foreword There is quite a bit of code here and it has taken a bit of time to process - especially the unit tests. I feel like the thoughts below will be incomplete but if I think of other ideas in ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
5 votes
Accepted

Tic-Tac-Toe code in JavaScript

Note, some of these require a build process the iife should be added in the build process, it's distracting The code doesn't expose anything. It's untestable. var should be let or const You can use ...
Magnus Jeffs Tovslid's user avatar
5 votes
Accepted

helper function to determine if html text is wrapped with a certain tag

Your code looks good and concise. Your test cases cover almost every branch of the code, which is also good. You can improve the variable names: The temp in <...
Roland Illig's user avatar
  • 21.3k
5 votes

Dynamically add/remove fields on input

Put styles in stylesheet, and use semantic markup. It's easier to think about the problem if it is a list of input controls. You would most probably want to reset the hidden inputs, because in case a ...
morbusg's user avatar
  • 900

Only top scored, non community-wiki answers of a minimum length are eligible