'Set Back ground colur when range has a certain value

I'm trying to prepare a snake like game in google sheets (https://docs.google.com/spreadsheets/d/1_of0OJWscvHDEFJkEGGgHrqVXCCOo_ikOYVEfpQsLHs/edit?usp=sharing)

I'm not really good with codes. Just trying to find some solutions to questions asked here before.

What I'm trying to do is..

  1. When "A" is clicked, the number randomly picked on "J2" (kind of dice action) cell is added in the "n" range.
  2. The total amount of group a (n2) will be selected from questions range (a1:h9) and will be colored yellow which will show the position of group A in the game pitch.

Follow up problems I will probably face...

  1. What can I do about backgroound colour when 2 groups are on the same number?
  2. how can I restrict result to 72? That is when a group is on "70" on the pitch and they roll the dice "3" or more the result will be over 72 but they should land on "72" as the last number on the pitch.
  3. How can I land the group on "28" when they actually reach "65" or land on "67" when they actually reach "35"

First part I could manage with the code below but 2nd part I couldn't do. 3. 4, and 5 I haven't searched anything yet as I couldn't finalise step 2

     function A() {
     var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SNAKE")
      var gvj1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SNAKE").getRange('J1')
      var hedef = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SNAKE").getRange('n1:n').getValues();
      var lrhedef = hedef.filter(String).length;
        var av = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SNAKE").getRange(lrhedef+1,14)
      av.setValue(gvj1.getValue()); // works for step 1

      // below I tried to check n2 value in a1:h9 and set background but couldnt
      var gpad = sheet.getRange("a1:h9").getValues();
      var apuan = sheet.getRange("n2").getValue();
       var values = sheet.getRange("E2:P243").getValues();
       var data = sheet.getDataRange().getValues();
       Logger.log(data)
        for(var i = 0; i<data.length;i++){
        for(var j = 0; j<6;j++){
        if(data[i][j] == apuan)
          return i+1;
          return j+1;
        }
      }
      //if (gpad==apuan){    

      ss.getRange([i+1][j+1]).setBackground('#6aa84f');

    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source