-1

I am new to google app script. I am attempting to create a basic function. This is what I have so far:

function PRQ(a,b)
{
  if(b=4)
  {
    return a*2
  }
  else 
  {
    return a*3
  }
}

This is the result of with b=4 and b not equal to 4:

a   b       
5   3       10
5   4       10

It is seeing the request to double the value in "a" but not the request to triple it. What am I doing wrong?

2 Answers2

2

You are using = within if statement,It will never execute to get desired result.

Here is working snippet:

function PRQ(a,b)
{
var result;
  if(b==4)
  {
        return a*2;
  }
  else 
  {
    return a*3;
  }

}

function main(){
PRQ(5,3)
}
S K
  • 442
  • 3
  • 5
0

Because you are using = instead of ==. = is assignment operator so your if condition always holds true in the code and it always returns a * 2.

Rajat Bhatt
  • 1,545
  • 15
  • 18