JSFiddle - React, Tailwind, and code Playground

by akang2

JavaScript

//edwin storefront challenge

    //the suits
    var suit = ['Hearts', 'Spades', 'Clubs', 'Diamonds'];
    
    //the ranks
    var rank = ['Ace', 2, 3, 4, 5, 6, 7, 8, 9, 'Ten', 'Jack', 'Queen', 'King'];
    
    //the empty deck array that will contain a combination of the suit and rank variables
    var deck = [];
    
    //create the regular deck
    var myDeck = function() {
      //combining the the suit and rank variables to generate the deck
      for(var s=0; s < suit.length; s++) {
        for(var r=0; r < rank.length; r++) {
          deck.push( rank[r] + " of " + suit[s] );
        }
      }
      console.log(deck);
    };
    
    //now shuffle the regular deck
    shuffleDeck = function(){
      for (j = 0; j < deck.length; j++) {
        k = Math.floor(Math.random() * deck.length);
        temp = deck[j];
        deck[j] = deck[k];
        deck[k] = temp;
      }
      console.log(deck);
    };

//run the deck generation function
myDeck();
//run the deck shuffle function
shuffleDeck();