RishiP
RishiP

Reputation: 1

Why does IF else google app script formula does not produce correct values?

I have a value in a google sheet which is "test2".

Using Google apps script I have created a custom formula TE using the formula below.

I input the formula in the adjacent cell =TE(test2), the value it outputs is incorrect. In the script below, it keeps picking up test 1 value always as -125 and the if statements are not working.

Please can anyone help?

function TE(AL) {

var RH = -110;
var HF = -30;
var AC = '';

if (AL = "test1") {
   AC = -125;
 } else if (AL = "test2") {
    AC = -135;
 } else {
    AC = -100000;
 }
 var TC = RH + HF + AC;


Logger.log (TC);

return TC;

}

Upvotes: 0

Views: 53

Answers (1)

Cooper
Cooper

Reputation: 64100

Try this:

function TE(AL) {
  var RH=-110;
  var HF=-30;
  var AC='';
  if(AL=="test1")
  {
    AC=-125;
  }else if(AL=="test2")
  {
    AC=-135;
  }else{
    AC=-100000;
  }
  var TC=RH+HF+AC;
  return TC;
}

Here's what it looks like on my spreadsheet:

enter image description here

Upvotes: 1

Related Questions