Google Sheets – IF OR Script

google sheetsgoogle-apps-script

So this is the code that I'm using for the script that I found;

function onOpen() {
  var s = SpreadsheetApp.getActive().getSheetByName('Todo');
  s.showRows(1, s.getMaxRows());

  s.getRange('D:D')
    .getValues()
    .forEach( function (r, i) {
    if (r[0] == 'X') 
      s.hideRows(i + 1);
    });
}

But I want it to hide the row if column D is X OR Y. I am not a programmer, and I'm very new to this. I have googled this to death but I'm not making any headway. Please help.

Best Answer

Try changing

if (r[0] == 'X') 

to

if (r[0] == 'X' || r[0] == 'Y' )