Skip to main content
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,795
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
8 votes
Accepted

Library project - javascript

I was in the midst of writing an answer, but ggorlen beat me to it. I echo most of those recommendations. Some additional considerations: No need to nest the Book ...
Greg Burghardt'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

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
  • 22.9k
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
  • 22.9k
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
6 votes

Library project - javascript

Avoid pointless comments that just restate what the code clearly does: //array where the new book objects are stored const myLibrary = []; ...
ggorlen's user avatar
  • 4,167
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

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,795
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,082
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.9k
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
  • 960
5 votes
Accepted

Extract HTML tags and its content from a string

Using regex to parse valid html will work (and you might call it beautiful) until it doesn't work... then you'll bend over backwards (over and over) each time you encounter an anomaly then try to ...
mickmackusa's user avatar
  • 8,802
5 votes

Webpage with a preload animation using JavaScript setTimeout

I would make the following recommendations to clean it up for future maintainability and readability: Clean up and remove the anonymous functions. They aren't really needed here and just create extra ...
Taco's user avatar
  • 929
5 votes
Accepted

Simple Password Generator in JavaScript

JavaScript You don't have to list down all characters. All printable characters in the ASCII range are found in 33-126. What you could do is generate a random number within this range, and convert ...
Joseph's user avatar
  • 25.4k
5 votes

Simple Calculator Script

Yes, It can be better in many ways just replace all your code with this: The first thing I did is made the code formatting just a bit better. then I added a title tag a webpage cannot go on without a ...
XYBOX's user avatar
  • 69
5 votes

Increment counter on button click

You say "How can I improve it without using a framework like jQuery, " There is no need to use a framework. Modern DOM APIs on all modern browsers have all you need to unilaterally access ...
Blindman67's user avatar
  • 22.9k
4 votes

Simple JavaScript library for DOM interactions

First off, consider which browsers is this DOM library supposed to support. Then test that it works in all of them. create() Plain for-in loop is not safe as it ...
Rene Saarsoo's user avatar
  • 2,082
4 votes
Accepted

jQuery Tab Scroller

This looks pretty good to me, is there a reason you have "use strict" inside every function in your js, but not in the beginning of the script instead? You might ...
Anton Kastritskiy's user avatar
4 votes

jQuery Tab Scroller

I agree with the advice of AntK - especially about use strict only required once. Another aspect to consider is that when applying CSS using .css() will alter the ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
4 votes
Accepted

Append multiple children to a node at once

First the code Some changes to improve the function. Node.prototype.appendChildren = function() { let children = [...arguments]; // old school ES6 way ...
Blindman67's user avatar
  • 22.9k
4 votes

HTML/Javascript Hex to RGB and RGB to Hex Color Converter

The code body asks about arrow functions, so I set out to write the converters with that in mind. In short, they can cut off clutter especially if you can make use of the implicit return value. ...
morbusg's user avatar
  • 960
4 votes

JavaScript Random Color Generator

Indentation If you look at the live snippet in your question you can see the indentation is not right for some places, but if you open the snippet editor it suddenly looks ok. That's because you didn'...
Isac's user avatar
  • 584

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