Challenge 19 Help (SOLVED)


#1

I’ve put in this code and it says that my code ran but did not produce the correct result. I can’t seem to figure out what’s wrong with my code. Can anyone help point me in the right direction? Here is my code:

function percentageReport(){
var percentageRock = (allRocks/gridSize)*100;
var percentRock = percentageRock.toFixed(2);
var percentageCurrent = (allCurrents/gridSize)*100;
var percentCurrent = percentageCurrent.toFixed(2);
var newArray = [percentRock, percentCurrent];
return newArray;
}


#2

Where do you define gridSize?


#3

It was a function from a previous challenge


#4

Add () to all the functions that you are using from any previous challenges since they’re not getting executed at all.


#5

You need to call functions properly as allRocks() and gridSize() I believe.


#6

Tried that, but changed gridSize to totalCells. This is what is looks like now, but still get the same error:

function percentageReport(){
var percentageRock = (allRocks()/totalCells())*100;
var percentRock = percentageRock.toFixed(2);
var percentageCurrent = (allCurrents()/totalCells())*100;
var percentCurrent = percentageCurrent.toFixed(2);
var newArray = [percentRock, percentCurrent];
return newArray;
}


#7

allRocks() returns a list of all your rocks in the grid, not a number. Same thing for allCurrents().


#8

Good catch, didn’t see that! As @kpalos mentions you would want to find the length of the array returned from your function.

i.e. (function().length/area)*100


#9

Thanks! Genius! That did the trick.