JSFiddle - React, Tailwind, and code Playground

by jfriend00

HTML

<div id="result"></div>

JavaScript

function getRandoms(numPicks) {
    var nums = [1,2,3,4,5,6,7,8,9,10];
    var selections = [];

    // randomly pick one from the array
    for (var i = 0; i < numPicks; i++) {
        var index = Math.floor(Math.random() * nums.length);
        selections.push(nums[index]);
        nums.splice(index, 1);
    }
    return(selections);
}


var results = getRandoms(4);
var output = results.join(", ");
document.getElementById("result").innerHTML = output;