Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Random number generator in JavaScript ⁉

84.2K views on YouTube

00:00:00 Math.random()
00:02:57 random number generator
00:06:37 multiple random numbers

// RANDOM NUMBER GENERATOR
const myButton = document.getElementById(“myButton”);
const label1 = document.getElementById(“label1”);
const label2 = document.getElementById(“label2”);
const label3 = document.getElementById(“label3”);
const min = 1;
const max = 6;
let randomNum1;
let randomNum2;
let randomNum3;

myButton.onclick = function(){
randomNum1 = Math.floor(Math.random() * max) + min;
randomNum2 = Math.floor(Math.random() * max) + min;
randomNum3 = Math.floor(Math.random() * max) + min;
label1.textContent = randomNum1;
label2.textContent = randomNum2;
label3.textContent = randomNum3;
}