JSFiddle - React, Tailwind, and code Playground

by Eugen Sunic

JavaScript

var stateArray = ["CO", "AK", "CA", "KY", "NM"];
  var selectedStates = [];
  var important = 6
  console.log('here')
  while (important < 9) {
    let j = Math.floor(Math.random() * 4);
    console.log(selectedStates)
    for (let i = 0; i < selectedStates.length; i++) {
      console.log(i)
      if (stateArray[j] == selectedStates[i]) {
        break;
      } else {
        selectedStates.push(stateArray[j]);
        console.log(selectedStates);
        important++
      }
    }
  }