Logging to the console randomly selected array values

I am new to coding, started about a week ago by using resources such as Mark Myers' book titled "A Smarter Way to Learn Javascript" and online tutorials. I wanted to experiment with something but so far did not succeed.

In a nutshell, I want to start with three arrays. Two of which will have three values each, and the third initially an empty array. I want each value of the first array to be concatenated with each value of the second array and the result added to the third - initially empty - array. Since the first and second arrays each contain three values, there will be nine combinations altogether, resulting in nine values in the third array.

What I want to achieve is to display one of the possible three combinations for each value of the first array. I want this to happen in a random fashion, using the statements the aforementioned book already covered, ones I am already aware of, without wandering into uncharted territories.

My approach was to create three random numbers, each of which represents a value (index, to be more exact) in the third array that will house the combinations (concatenations) of the first and second arrays. Thus, I wanted the first random number to be either 0, 1 or 2 to "choose" a possible combination for the first value of the first array, the second random number to be either 3, 4 or 5 to choose a possible combination for the second value of the first array, and finally, a third random number, either 6, 7 or 8 to point to a combination for the third value of the first array.

The goal was to log the randomly selected combinations (concatenations) - one for each value of the first array - in the console. In other words, I am expecting to see three concatenations in the log. However, the console only returns one concatenation.

Can someone please shed some light what exactly is missing or wrong? I believe the problem in my code lies in the last line but so far cannot figure out what exactly is the issue. I am also unsure why Visual Studio Code (I am using the "Prettier" extension) modifies my formatting of the last line from

console.log(strNum[num1, num2, num3]);

to

console.log(strNum[(num1, num2, num3)]);

upon saving the file but maybe this has nothing to do with my issue.

My code is the following:

// Declaring variables for the operation
var str = ["a ", "b ", "c "]; // Array str to hold strings a, b and c
var num = ["1", "2", "3"]; // Array num to hold numbers 1, 2 and 3
var strNum = []; // Array strNum to hold all possible combinations of array str and array num
var k = 0; //Counter for array strNum

// Combining the contents of array str and array num and adding the combinations to array strNum
for (i = 0; i < str.length; i++) {
  for (j = 0; j < num.length; j++) {
    strNum[k] = str[i] + num[j];
    k++;
  }
}

// The first random number between with the possible values 0, 1 or 2, to determine the first pair
var bigDecimal1 = Math.random();
var improvedDecimal1 = bigDecimal1 * 3;
var RandomNum1 = Math.floor(improvedDecimal1);

// The second random number between with the possible values 3, 4 or 5, to determine the second pair
var bigDecimal2 = Math.random();
var improvedDecimal2 = bigDecimal2 * 3 + 3;
var randomNum2 = Math.floor(improvedDecimal2);

// The third - and last - random number between with the possible values 6, 7 or 8, to determine the third pair
var bigDecimal3 = Math.random();
var improvedDecimal3 = bigDecimal3 * 3 + 6;
var randomNum3 = Math.floor(improvedDecimal3);

console.log(strNum[(num1, num2, num3)]);

Prettier tries to correct your code. You can't have console.log(strNum[num1, num2, num3]), as you can only pick one element from an array at a time. strNum[num1] should work fine, as you pass a number (this is the index of the element).

When you provide more than one variable, Prettier tries to group what's inside the square brackets. That's why it adds the grouping operator (extra parentheses).

You can pick one element at a time like this:

function random(min, max) {
  return Math.floor((Math.random() * ((max - min) + 1)) + min);
}

let first = random(0, 2);
let second = random(3, 5);
let third = random(6, 8);

// Declaring variables for the operation
let str = ["a ", "b ", "c "];
let num = ["1", "2", "3"];
let strNum = [];
let k = 0;

// Combining the contents of array str and array num and adding the combinations to array strNum
for (let i = 0; i < str.length; i++) {
  for (let j = 0; j < num.length; j++) {
    strNum[k] = str[i] + num[j];
    k++;
  }
}

console.log(strNum[first], strNum[second], strNum[third]);
// Or you can log a new array
console.log([strNum[first], strNum[second], strNum[third]]);

I also created a random() function so you don't have to repeat yourself. And please, don't make global variables. Declare the i and j inside your for loops.