Help with Challenge #13


#1

Help! I tested my code using Chrome Console (and other online tools) and it runs fine without errors, but the lighthouse keeps saying : “Your code ran but did not produce the correct result.”.

Chrome Console:
allRocks();
(9) [“D1”, “E3”, “F3”, “E4”, “F4”, “B8”, “H8”, “B9”, “B10”]
allCurrents();
(7) [“E2”, “C8”, “D8”, “D9”, “E9”, “E10”, “F10”]

My Code:

const COORDINATES = [
[“A1”, “B1”, “C1”, “D1”, “E1”, “F1”, “G1”, “H1”, “I1”, “J1”],
[“A2”, “B2”, “C2”, “D2”, “E2”, “F2”, “G2”, “H2”, “I2”, “J2”],
[“A3”, “B3”, “C3”, “D3”, “E3”, “F3”, “G3”, “H3”, “I3”, “J3”],
[“A4”, “B4”, “C4”, “D4”, “E4”, “F4”, “G4”, “H4”, “I4”, “J4”],
[“A5”, “B5”, “C5”, “D5”, “E5”, “F5”, “G5”, “H5”, “I5”, “J5”],
[“A6”, “B6”, “C6”, “D6”, “E6”, “F6”, “G6”, “H6”, “I6”, “J6”],
[“A7”, “B7”, “C7”, “D7”, “E7”, “F7”, “G7”, “H7”, “I7”, “J7”],
[“A8”, “B8”, “C8”, “D8”, “E8”, “F8”, “G8”, “H8”, “I8”, “J8”],
[“A9”, “B9”, “C9”, “D9”, “E9”, “F9”, “G9”, “H9”, “I9”, “J9”],
[“A10”, “B10”, “C10”, “D10”, “E10”, “F10”, “G10”, “H10”, “I10”, “J10”],
];

function allRocks() {
var rocksCells = [];
for (row = 0; row < GRID.length; row++) {
for (col = 0; col < GRID[0].length; col++) {
if (GRID[row][col] == “^”) {
rocksCells.push(COORDINATES[row][col]);
}
}
}
return(rocksCells);
}

function allCurrents() {
var currentsCells = [];
for (row = 0; row < GRID.length; row++) {
for (col = 0; col < GRID[0].length; col++) {
if (GRID[row][col] == “~”) {
currentsCells.push(COORDINATES[row][col]);
}
}
}
return (currentsCells);
}


#2

PROBLEM FOUND…

Code only worked for 10x10 grids. Using COORDINATES array was not a good idea.

One solution that worked is to build the coordinate usinh an ALPHABET string.
rocksCells.push(ALPHABET[col].toUpperCase() + (row + 1));