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 ...
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:
...
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 ...
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 ...
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 ...
6
votes
Accepted
Truncating text with jQuery but keep the HTML formatting
First of all, I would just like to say that this is a really good and useful function. From a Code Review standpoint, there are almost no errors in it that I know of. Here are a few things I found ...
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 ...
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 ...
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 ...
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:
...
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 ...
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 ...
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 ...
6
votes
Accepted
Refactor JavaScript nested if-else
As already suggested, you can abstract common logic to a function:
...
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 ...
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 ...
5
votes
Converting partial XML (Node List) to a String
Reading the documentation for
Transformer,
where it says:
A Transformer may be used multiple times. Parameters and output
properties are preserved across ...
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.
...
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.
...
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 ...
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 ...
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.
...
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 ...
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:
...
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....
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&...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
dom × 405javascript × 363
html × 116
jquery × 96
beginner × 45
event-handling × 44
css × 42
ecmascript-6 × 37
form × 22
performance × 21
animation × 17
object-oriented × 13
game × 13
xml × 13
php × 12
html5 × 12
java × 11
ajax × 10
to-do-list × 10
datetime × 8
typescript × 8
recursion × 7
image × 7
json × 6
tic-tac-toe × 6