I have the followng issue with switch case statement. I have a variable named combineDirection with a changing index value each time a user types a value in the input field. The switch statement is supposed to match index of variable to case value and then slice arrays mentioned in firstRow, secondRow and thirdRow accordingly. I cannot seem to return the correct concatenation of array’s and there given indexes . The variable testVal is a number a user inputs that could be 1 or up to number 9. Stored in the firstRow , secondRow and thirdRow variables. Here is my code. Thanks in advance for youre advice with this issue.
let testVal = 1;//Can be any number between 1 and 9.
let multiArray = [
[ '..9..5.1.' ],
[ '85.4....2' ],
[ '432......' ],
[ '1...69.83' ],
[ '.9.....6.' ],
[ '62.71...9' ],
[ '......194' ],
[ '5....4.37' ],
[ '.4.3..6..' ]
];
let flagMe = true;
let combinedDirection = multiArray[0][0][0];//variable with array index keeps changing with user input.
switch(combinedDirection){
case multiArray[0][0][0]:
case multiArray[0][0][1]:
case multiArray[0][0][2]:
case multiArray[1][0][0]:
case multiArray[1][0][1]:
case multiArray[1][0][2]:
case multiArray[2][0][0]:
case multiArray[2][0][1]:
case multiArray[2][0][2]:
firstRow = multiArray[0][0].slice(0,3);
secondRow = multiArray[1][0].slice(0,3);
thirdRow = multiArray[2][0].slice(0,3);
break;
case multiArray[0][0][3]:
case multiArray[0][0][4]:
case multiArray[0][0][5]:
case multiArray[1][0][3]:
case multiArray[1][0][4]:
case multiArray[1][0][5]:
case multiArray[2][0][3]:
case multiArray[2][0][4]:
case multiArray[2][0][5]:
firstRow = multiArray[0][0].slice(3,6);
secondRow = multiArray[1][0].slice(3,6);
thirdRow = multiArray[2][0].slice(3,6);
break;
case multiArray[0][0][6]:
case multiArray[0][0][7]:
case multiArray[0][0][8]:
case multiArray[1][0][6]:
case multiArray[1][0][7]:
case multiArray[1][0][8]:
case multiArray[2][0][6]:
case multiArray[2][0][7]:
case multiArray[2][0][8]:
firstRow = multiArray[0][0].slice(6,9);
secondRow = multiArray[1][0].slice(6,9);
thirdRow = multiArray[2][0].slice(6,9);
}
combineMe = [...firstRow,...secondRow,...thirdRow];
console.log(combineMe);
[...combineMe].forEach((el,index)=>{
if(el == testVal){
flagMe = false
}
})