skip to Main Content

I have a list with a drop down menu and each selection effects multiple variables.
is there any way to refine it down? here is a snippet:

if (selectedLeft == 'item 1')
  row1Vis = false;
if (selectedLeft == 'item 1')
  leftCounter = false;
if (selectedLeft == 'item 1')
  leftNA = true;

is it possible to have it something like,
if (selectedLeft == ‘item 1’)
row1Vis = false, leftCounter = false, leftNA = true;

so i don’t have to write out if (selectedLeft == ‘item 1’) 3 times.

cheers

2

Answers


  1. You can use body (){...}

    if (selectedLeft == 'item 1') {
      row1Vis = false;
      leftCounter = false;
      leftNA = true;
    }
    

    More about if-and-else , switch-and-case on language-tour

    Login or Signup to reply.
  2. You can use the if body for your variable and also use &&, || if you want to use two or more conditions. && means AND, || means OR:

    if(selectedLeft == 'item 1' && selectRight == 'item 2') {
      row1Vis = false;
      leftCounter = false; 
      leftNA = true; 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search