Challenge #13 - Your code ran but did not produce the correct result


#1

Hello guys,

I’m getting the correct output but when I submit the code it gives the message “Your code ran but did not produce the correct result.”. I can’t figure out what is going wrong. Do you guys have any clue?

function allRocks(){
let rocks = [];
for (row = 0; row < countRows(); row++){
for (column = 0; column < countColumns(); column++){
if(GRID[row][column] === “^”){
rocks.push(String.fromCharCode(column + 65)+(row + 1));
}
}
}
}

function allCurrents(){
let currents = [];
for (row = 0; row < countRows(); row++){
for (column = 0; column < countColumns(); column++){
if(GRID[row][column] === “~”){
currents.push(String.fromCharCode(column + 65)+(row + 1));
}
}
}
}


These are the outputs:
Array(9) [“D1”, “E3”, “F3”, “E4”, “F4”, “B8”, “H8”, “B9”, …]
Array(7) [“E2”, “C8”, “D8”, “D9”, “E9”, “E10”, “F10”]



#2

question. Are you adding a return to your function? I dont see them above but I dont know how you’d get the output otherwise


#3

Hello Kay! You’re totally right!!! I got involved in the problem and forgot the return :joy::joy::joy: what a mess!!

Thank you so much for your time and attention!


#4

Same error different issue I have tried a bunch of stuff but am sure i am missing something.

function allRocks(){
  var alphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'];
  var all = [];
    for (let i = 0; i < countRows(); i++) {
      for (let a = 0; a < countColumns(); a++) {
          var col = alphabet[a];
          var row = ++i;
          var cor = col + row;
        if (isRock(cor)){

          all.push(cor);
    }
}
  
}
  return all;
}

function allCurrents()
{
    var alphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'];
    var all = [];
    
    for (let i = 0; i < countRows(); i++) {
      for (let a = 0; a < countColumns(); a++) {
            var col = alphabet[a];
            var row = ++i;
            var cor = col + row;
        if (isCurrent(cor))
        {
            all.push(cor);
        }
      }
    }
    return all;
}

#5

Can we see your isRock() and lightCell() as well? Might help to determine what is occurring.

Edit: Not super familiar with increments/javascript but can you set the increment directly into a variable? var row = ++i;

Consider trying var row = i +1; then it will take the current point in the loop and account for zero index array will it not?


#6

Try out @C_Slater’s suggestion.

Look at the expression ...(let i = 0; i < countRows(); i++) vs. var row = ++i;.

Check out this article on JS incrementing/decrementing.

Good luck!


#7

This might not be it, but. Why does your alphabet only go to T? The code needs to work for grids up to 26 letters across.


#8

After the first time you declare a variable, you don’t need to declare it again.

You can do:

var i = 0
i++

Try it in the console, you will see that i now has a value of 1.

You can do the same with any variable:

var row = 0
row++