Hot answers tagged

14 votes
Accepted

Lights on: playing with buttons in Javascript

I'll just start by looking at what you have, and then I'll get to your questions. (Edit: Seems I'm retreading a lot of what SirPython already covered. Didn't see that answer before I posted. Apologies ...
user avatar
  • 32.9k
11 votes
Accepted

forEach and NodeList

The only purpose of this script appears to be to illustrate the use the Array.prototype.slice.call "idiom" and the forEach ...
user avatar
  • 32.9k
9 votes

Lights on: playing with buttons in Javascript

HTML In HTML, the property values should always be encased in ""s, even if the type is not necessarily intended to be a string. If needed, the JavaScript ...
user avatar
  • 13.2k
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 ...
user avatar
  • 1,765
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: ...
user avatar
  • 16.4k
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 ...
user avatar
7 votes

Lights on: playing with buttons in Javascript

For a beginner, it isn't bad. There are some rough points to fix, but nothing serious! Lets tackle by language: HTML: The first thing I've noticed is your doctype: ...
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 ...
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 ...
user avatar
6 votes

New Game - Am I going down the right path for DOM manipulation?

Personally instead of using .find I prefer passing context to the jQuery selector like this; ...
user avatar
  • 2,291
6 votes

forEach and NodeList

Just two minor notes to add @Flambino's great answer: Instead of x use intention-revealing names. What's the purpose of this variable? Name according to that. <...
user avatar
  • 29.7k
6 votes

Updating Grid on Webpage (new version)

Overall it looks pretty clean, I'd like to see some comments on the functions so I know what they do without having to read the code, you could use JSDoc for this. I'd recommend explicitly using ...
user avatar
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 ...
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 ...
user avatar
  • 32.9k
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: ...
user avatar
  • 4,205
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 ...
user avatar
  • 19.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 ...
user avatar
  • 19.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 ...
user avatar
6 votes
Accepted

Refactor JavaScript nested if-else

As already suggested, you can abstract common logic to a function: ...
user avatar
5 votes

Implementing an algorithm that walks the DOM without recursion

Here is a solution that is about as concise as your recursive solution. (8 lines of code.) ...
user avatar
  • 151
5 votes

Updating Grid on Webpage

Just a couple of things that I really feel strongly about (didn't work line for line through your code though). Seperation of logic and presentation Yes, there is a ...
user avatar
5 votes
Accepted

Horizontal menu for 3 items

Template The first thing that comes into mind when building widgets is how the HTML is written. I'd avoid the HTML concatenated strings in JS. They're just so messy. I prefer templates instead, like ...
user avatar
  • 24.8k
5 votes

Updating Grid on Webpage (new version)

Chris Thomson's answer makes some very good points about the overall quality, and Leopoldo Salvo's answer points out several hidden issues with the timer(s) and event handling. My comments will be ...
user avatar
  • 32.9k
5 votes
Accepted

Updating Grid on Webpage (new version)

I would not hard code 'container', instead make it an attribute of gridOptions : var options = { .... containerClass = 'container', .... } I would ...
user avatar
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 ...
user avatar
  • 1,765
5 votes
Accepted

Simple todo list

Don't pollute the global namespace. You have 1 variable and 3 functions all going into the global namespace. This is especially a problem because of the generic names you have. So they could be ...
user avatar
  • 1,042
5 votes

jQuery selector function in JavaScript

First off, you have a bug. On the line if (tagElemCollection[i].id != "") {, you used the != operator instead of the ...
user avatar
5 votes

Filling in comment replies when link is clicked

jQuery's docs for .parent(): You can specify a selector to find a specific ancestor. Or you can use the .parents() method to ...
user avatar
  • 32.9k
5 votes
Accepted

Generate form and append to the body

...
user avatar
  • 13.2k
5 votes
Accepted

HTML and JS to dynamically load, refresh, and execute JavaScript from external file

This code is very clean, and I believe that it is a very useful tool for any JavaScript developer. This is not very efficient: ...
user avatar
  • 13.2k

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