JSFiddle - React, Tailwind, and code Playground
by akang2
JavaScript
//Act 7.1 Nested loops
var suits = ['Hearts', 'Spades', 'Clubs', 'Diamonds'];
var ranks = ['Ace', 2, 3, 4, 5, 6, 7, 8, 9, 'Ten', 'Jack', 'Queen', 'King'];
var deck = [];
/*
for(i=0;i<suits.length;i++) {
//this accesses the variable "suits" at the current index in the loop
suits[i]
}
for (i=0; i < ranks.length, i++) {
console.log(ranks[i]);
}
*/
//In order for us to be able to use the values from both loops, we need to nest one inside the other. Doesn't matter which one you nest in which, just gotta nest them
for(i=0;i<suits.length;i++) {
//this accesses the variable "suits" at the current index in the loop
//suits[i];
//Notice in this loop though, we change the variable "i" to "r" because we don't want it to conflict with the original "i" variable
for (r=0; r < ranks.length; r++) {
console.log(ranks[r] + " of " + suits[i]);
}
}