I’m generating random numbers from 1 to 20 by calling generateRandom(). How can I exclude some values, say 8 and 15? Answer it should be or instead of and
Tag: javascript
Term.js – page scrolls down to the section with the terminal
This is probably a silly question – I’m using term.js to simulate a linux terminal. Everything works fine. The only issue I am having is – the page where I have embedded it is pretty long and this terminal is somewhere at the bottom – but as soon as the page loads – it automatica…
Object destructuring without var, let or const
Why does object destructuring throw an error if there is no var keyword in front of it? throws SyntaxError: expected expression, got ‘=’ The following three examples work without problems Bonus question: Why do we not need a var for array destructuring? I ran into the problem doing something like …
Pickadate Time Selector Disappears on Click on JQuery UI Dialog
If you open a time picker in a jQuery dialog using the classic theme and try to use the time picker scroll bar to move down the time list, the time list disappears. You can see the issue here: http://jsfiddle.net/7c2z840a/7/ The problem appears in both Chrome and Firefox, but not in IE. Anyone have any ideas …
Regex for matching HashTags in any language
I have a field in my application where users can enter a hashtag. I want to validate their entry and make sure they enter what would be a proper HashTag. It can be in any language and it should NOT precede with the # sign. I am writing in JavaScript. So the following are GOOD examples: Abcde45454_fgfgfg (good…
How do I optimally distribute values over an array of percentages?
Let’s say I have the following code: To find out how to equally distribute a hundred over the array is simple, it’s a case of: Or doing it using a for loop: However, let’s say each counter is an object and thus has to be whole. How can I equally (as much as I can) distribute them on a differ…
how to render multiple children without JSX
How to write this without using JSX? This comes from the react.js tutorial: http://facebook.github.io/react/docs/tutorial.html I know I can do the following: But this only adds one element. How can I add more next to one another. Answer You can use the online Babel REPL (https://babeljs.io/repl/) as a quick w…
jshint Error: Cannot find module ‘underscore’
My grunt task seems to be running perfectly fine, but every time I run it I’m getting this error: Is there any way to find out why this is happening? I can see the /grunt-contrib-jshint directory is in the /node_modules directory. Is there any reason it can’t find the underscore module? I’ve…
Parse.com relations count
I want to query object from Parse DB through javascript, that has only 1 of some specific relation object. How can this criteria be achieved? So I tried something like this, the equalTo() acts as a “contains” and it’s not what I’m looking for, my code so far, which doesn’t work: …
react.js: removing a component
I’m fairly new at react.js, so any help is greatly appreciated. I have this: https://jsfiddle.net/rzjyhf91/ Wherein I have made 2 components: an image and a button. The goal is to remove the image with a click of the button, I use unmountComponentAtNode for that, but it does not work: How can I remove a…