title: change values in variables if a certain variable contains a certain string?
body: <p><a href="https://i.stack.imgur.com/wnSGj.png" rel="nofollow noreferrer">In my excel spreadsheet I have students and LDI Year field.</a></p>
  
  <p>I have created a new variable called studentandYear which creates a new string containing the name and year. With the year value in the studentandYear variable I want to be able to make another variable called tag which contains the value "year LDI". You should be able to switch the value of the tag depending on what year it is.</p>
  
  <p>when I console log the tag value I only get one the first tag back called "2019 LDI" however the second tag is not showing up on the console.log. could someone please help?</p>
  
  <pre><code>function myFunction() {
  
    var ss = SpreadsheetApp.getActive().getSheetByName("Studentlist");
    var lr = ss.getLastRow();
    var date = new Date();
    var day = date.getDate();
    var month = date.getMonth()+1;
    var year = date.getFullYear();
    var time = date.toLocaleTimeString();
  
  
    if(day &lt; 10)
      day = "0" + day;
  
    if(month &lt; 10)
      month = "0" + month;
  
    var dateString = day+"/" + month +"/"+year+ " - " + time;
  
    for( var i = 2; i&lt;=lr ;i++ ) {
  
      var student = ss.getRange(i, 1).getValue();
      var year = ss.getRange(i, 2).getValue();
  
      var studentandYear = student + ' '+ year;
  
      var tag = "";
  
  
      if(studentandYear.indexOf("2019")){
  
        tag = "2019 LDI"
  
  
      } else if(studentandYear.indexOf("2020")){
  
         tag = "2020 LDI"
  
  
      }
            Logger.log(tag)
  
    }
  
  
  
  
  }
  </code></pre>