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
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 ...
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 ...
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
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 ...
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 = [];
...
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
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
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
...
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.
...
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'...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
dom × 403javascript × 362
html × 115
jquery × 98
beginner × 44
css × 43
event-handling × 42
ecmascript-6 × 36
form × 22
performance × 20
animation × 17
object-oriented × 13
game × 13
xml × 13
php × 12
html5 × 12
java × 11
ajax × 10
to-do-list × 10
datetime × 8
recursion × 7
image × 7
typescript × 7
json × 6
react.js × 6