jeudi 25 juillet 2019

multiple OR conditions in IF statement in javascript

I have a drop-down and depending on what is selected from the drop-down some of the UI fields will become un-visible to the user to fill. I have an IF statement with many different ORs and have the hard-coded value on the condition. I am very new to coding so I don't know what is the best way to do this. I want to have a clean and reusable code. Also the drop-down values are coming from the database and I did not know how to add to my IF without hard-coding them.
Any help will be appreciated.

if (value === 'Banana Factory' || value === 'Apple Factory ') {
      this.store1Visable = false;
    } else {
      this.store1Visable = true;
    }
    if (value === 'Pineapple Factory' || value === 'Peanut Factory' || value === 'Kiwi Factory' || value === 'Watermelon Factory') {
      this.store2Visable = false;
    } else {
      this.store2Visable = true;
  }
    if (value === 'Pineapple Factory' || value === 'Peanut Factory' || value === 'Kiwi Factory' || value === 'Watermelon Factory'
        || value === 'Banana Factory' || value === 'Grape Factory' || value === 'Peach Factory' || value === 'Kiwi Factory') {
      this.store3Visable = false;
    } else {
      this.store3Visable = true;
    }
    if (value === 'Pineapple Factory' || value === 'Peanut Factory' || value === 'Kiwi Factory' || value === 'Watermelon Factory'
        || value === 'Banana Factory' || value === 'Grape Factory' || value === 'Peach Factory') {
      this.store4Visable = false;
    } else {
      this.store4Visable = true;
    }

I want my code to be clean and reusable to the point if something needs to be added it be an easy change.

Aucun commentaire:

Enregistrer un commentaire