Problems creating a nested loop that properly reads a multi-dimensional array and creates an out

I am an amateur coder who is trying to create a battleship style app. To do so, I am utilizing a multidimensional array which stores the location of Sheep and and also clicks. I created a looped onEvent which allows me to use a single onEvent to click any one of my 16 buttons. To read the array to place the Sheep in an array spot coordinating with the click on the array, I created the function placeSheep. While created place sheep, I was feeding it the string “test” but now that I am attempting to feed it the value supplied by the event.targetId command, nothing at all happens.

Additionally, even when I can get the function to operate, the resulting output is one that is a string and cannot be read as a value coordinating to an array.

Can you help me fix my function?

This is the looped onEvent that calls placeSheep

for (var i = 1; i<=16; i++){
  var buttonName = i;
  onEvent (buttonName, "click", function (event) {
    var iD = (event.targetId);
    var id = ("i"+iD);
    if (gameMode === 0){
      checkSheep (id);
      console.log ("lol u failed");
    } else {
      placeSheep (iD);

This is the placeSheep function

function placeSheep (iD){
  for(var x =0; x<player2Grid[0].length; x++){
    for (var y = 0; y<player2Grid[0][x].length; y++){
      if (iD===player2Grid[0][x][y]){
        playerSheep1 = "[0]["+x+"]["+y+"]";
        var playerSheep1Location = "player2Grid" + playerSheep1;
        console.log (playerSheep1Location);