This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This gist is for Javascript beginners. | |
* @author: Anthony Du Pont <[email protected]> | |
* @site: https://www.twitter.com/JsGists | |
* @source: Coding Math/Keith Peters | |
* | |
* You often get floating numbers in Javascript and sometimes you need to round them and | |
* keep only n decimals. They are many solutions to do so but let me show you my favorite. | |
* | |
* Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This gist is for Javascript beginners. | |
* @author: Anthony Du Pont <[email protected]> | |
* @site: https://www.twitter.com/JsGists | |
* | |
* You need sometimes to format you number and one of the common way to format them is to add a leading zero | |
* to numbers less than 10. There is many ways of doing this so let me show you some of them. | |
* | |
* Example: | |
* I have a number and I want to prepend a 0 to it if it's less than 10. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This gist is for Javascript beginners. | |
* @author: Anthony Du Pont <[email protected]> | |
* @site: https://www.twitter.com/JsGists | |
* | |
* The idea is to get a random node/entry from a given array. | |
* | |
* Example: | |
* I can't choose which fruit I'll eat this afternoon, they all look so tasty so I'll simply close my eyes | |
* and choose one of them randomly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This gist is for Javascript beginners. | |
* @author: Anthony Du Pont <[email protected]> | |
* @site: https://www.twitter.com/JsGists | |
* | |
* The `Math.random()` method only return a random number between 0 and 1. | |
* But what if you want a larger range than [0, 1] ? We need to improve this | |
* random method. | |
* | |
* Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This gist is for Javascript beginners. | |
* @author: Anthony Du Pont <[email protected]> | |
* @site: https://www.twitter.com/JsGists | |
* | |
* Methods like `querySelectorAll()` are handy to select multiple DOM elements at once. | |
* But these methods return a `NodeList` which is a list of all the matching DOM elements. | |
* No problem at first glance but when you dig a little bit you'll notice there are some | |
* issues when you want to manipulate them. | |
* |
NewerOlder