Let’s say I have an array of 100 integers that looks like this: let hundred = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, … Continue reading JavaScript: How to get a random index from an array
Math.random()
JavaScript: How to generate an array of random numbers
Let’s say I want to create a list of 10 numbers that are between the values of 0 and 1. This can be done with a simple for loop. For example: let length = 10; let max = 1; let randArray = []; for (i=0; i < length; i++) { randArray.push(Math.random(max)); } console.log(randArray); Setting the … Continue reading JavaScript: How to generate an array of random numbers
JavaScript: Demo of getElementById( )
Here is some JavaScript code that demonstrates how to use JavaScript to change HTML text on a page by clicking a button. When the button is clicked, the text is replaced with a random quote. Reset Demo This example uses DOM elements innerHTML and document.getElementById(). It also uses a couple of Math functions such as … Continue reading JavaScript: Demo of getElementById( )