I'm a student and very new to coding, I'll try my best to explain the issue i'm having. So I have an array which I want to show up as buttons on my page using jquery. Each button needs to be assigned a random value between 1 and 12. I have a for loop going through the buttons assigning a random value. I got that to work. My problem however, is that I don't want any of the buttons to contain the same value. So if the first button generates a random value of "2" I don't want any of the last 3 buttons to contain a value of "2". Here is my code so far. Any help would be greatly appreciated.
$(document).ready(function () {
// Create random number between 19 and 120
var number = Math.floor(Math.random() * (120 - 19 + 1) + 19);
console.log(number);
//show random number to user
var randomNumberField = $("#randomNumber");
randomNumberField.text(number);
//Create crystals/buttons
var Crystals = [1, 2, 3, 4];
for (var i = 0; i < Crystals.length; i++) {
var crystalNumber = Math.floor(Math.random() * (12 - 1 + 1) + 1);
console.log(crystalNumber);
if ($("crystalNumber") === $("Crystals")) {
crystalNumber = Math.floor(Math.random() * (12 - 1 + 1) + 1);
};
else(var i = 0; i < Crystals.length; i++)
var crystalImage = $("<img>");
}
}); // end of script