Challenge 18 ideas [Solved]


#1

What do you guys got?


#2

I did a two checks on the cell using isRock, and isCurrent from previous challenges. Then I return the appropriate value for each cases where if it is a rock, or if it is a current or it is neither.


#3

What is wrong with this logic?

function howDangerous(coordinate){

  if (isRock(coordinate)) {
    return 100;
  } else if (isCurrent(coordinate)) {
    return 50;           
  } else {
    return false;
  }
}

howDangerous('E3');

console.log(howDangerous('E3'));

The if (isRock(coordinate)) checks if it’s true… so based on the previous function, if it’s a rock, it should be true, same for isCurrent.

So if it’s true, it should return 100, for current 50. and for everything else, false.

Currently it returns false.

Any help?


#4

I think the challenge says it has to return a number, try returning 0 instead of false. That may work.


#5

Nope, it returns 0…


#6

Oh sorry, misread what your wrote, will look again.


#7

I copied your ‘howDangerous’ function into the test environment I was using and your logic gave me:

E1 = false
E2 = 50
E3 = 100

Which is correct.


#8

Hmm, so that means that it’s my isRock function that is wrong, or maybe my lightCell function…


#9

Can you check if this works…(My laptop stopped working and I had to copy the code from lighthouse labs editor and may have made some mistakes.

This is my lightCell function… It might be a problem from when they asked us to update the lightCell function… I just made a new one and commented out the first one.

function lightCell(coordinate){
    return GRID[(convertColumn(coordinate))][convertColumn1(coordinate)];
}

lightCell('B4');
console.log(lightCell('B4'));

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

function lightCell(coordinate){
    if (convertColumn(coordinate) > countColumns()) {
        return false;
    } else if (coordinate[1] > countRows()) {
        return false;
    } else {
        return true;
    }
}

lightCell('Z3');

console.log(lightCell('Z3'));

This is my isRock function

function isRock(coordinate){
    if (lightCell(coordinate) === '^') {
        return true;
    } else {
        return false;
    }
}

isRock('D1');

console.log(isRock('D1'));

#10

Its your lightCell that isn’t working.

isRock worked fine.


#11

Just to confirm you have changed your last else statement which contains your final return statement from:

return false;

to

return 0;

Not sure about the return value type when the LHL code check runs, but if they are looking for an integer returned then your return of false may be the issue.


#12

Sorry, I forgot to mention, I have a similar structure that returns 0 (as an int) and my code passed.


#13

Yep I changed to zero… Now I think it might have to do with my lightCell function. I might have fucked up when I updated it.


#14

Just sent you my relevant code to see if that helps you.


#15

THANK YOU THANK YOU THANK YOU!! I completely forgot we changed the lightCell function from before! That had me stuck. What I did was I went around the calling up of the isRock AND isCurrent functions and just converted the coordinates, pulled up the contents from GRID, and then did the logic checks (i.e GRID[i][j] === “^”) in the if statements.


#16

Ok, so I changed, some stuff, now it works on the editor, but i had to remove my updated lightCell function and just keep the base one.

So it means it’s the update on the lightCell function who was creating a problem… At least now i know what to look at.


#17

SOLVED IT !!!

Thanks everybody for the help!!!

So essentially, I made a mistake while converting the Rows to -1 to adjust for the “0 Indexing”, which carried on to the rest of the code… And then, I didn’t update properly the lightCell function.

Everything is good now.


#18

Did you revert back to the original code for lightCell (the one used before the update)? Does doing that affect our previous challenge outcome?


#19

Before this challenge, I had two lightCell functions. One that would return what was at a certain coordinate in the GRID, and one that would return false if the coordinate given (either letter or number) wasn’t part of the GRID.

So I ended up just combining both together as I think was the way to do it initially (but couldn’t figure it out at the time for some reason).

So now I only have one that returns false if the column given is larger then the actual number of columns; returns false if the number of rows given is larger then the actual number of rows; and returns what is at that position if the coordinate is good.