'If else if statement for variable to another variable

I need to have a Google Form that returns the result of variable2 depends on the result of variable1. The code runs successfully but the variable 2 does not change.

No matter what the value of BranchChoices is, the result will always be LN2. Did I missed out anything?

   item = "Branch"; 
   var bN2 =  ["A", "B", "C"]
   var bN1 = ["1", "2"]
   var bN3 = ["1", "2", "A", "B", "C"]
   var BranchChoices = bN3;  
   form.addMultipleChoiceItem()  
       .setTitle(item)  
       .setChoiceValues(BranchChoices)  
       .setRequired(true); 
 
   item = "Location";   
   var LN1 = ["I"];  
   var LN2 = ["P"]; 
   var LN3 = ["I:", "P:"]; 
   
   if(BranchChoices = bN2) {
     var LocationChoices = LN2;
     } else if (BranchChoices = bN1) {
     var LocationChoices = LN1 ;
     } else if (BranchChoices = bN3) {
     var LocationChoices = LN3 ;
     }

   form.addMultipleChoiceItem()  
       .setTitle(item)  
       .setChoiceValues(LocationChoices)  
       .setRequired(true);


Solution 1:[1]

The difference between assignment and conditional

This is an assignment if(BranchChoices = bN2) {

This is probably what you really want if(BranchChoices == bN2) {

You made the same error in several places fix them all. There may be other errors. You code is incomplete.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Cooper