4 Replies Latest reply on Aug 30, 2017 12:03 PM by soulglowdeej

    What have I done wrong with this IF statement?

    soulglowdeej Level 1

      Hi,

       

      I'm trying to get a certain buttons to appear depending on score returned in a  given box...but it's not working.

      I can get it to work when there are fewer options and threescore is a > thing, but equal to and more options, I'm struggling with.

      Can anyone see where i've gone wrong?

       

      var nResult = this.getField("score").value;

      if ( nResult = 200 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.visible;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 160 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.visible;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 151 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.visible;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 40 ) {

      this.getField("adventure_seeker").display = display.visible;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 31 ) {

      this.getField("adventure_seeker").display = display.visible;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 80 ) {

      this.getField("adventure_seeker").display = display.visible;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 71 ) {

      this.getField("adventure_seeker").display = display.visible;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 4 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.visible;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 13 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.visible;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 53 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.visible;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 62 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.visible;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 22 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.visible;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 102 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.visible;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.hidden;

      }

      else if ( nResult = 120 ) {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.visible;

      this.getField("no_score").display = display.hidden;

      }

      else {

      this.getField("adventure_seeker").display = display.hidden;

      this.getField("mountain_climber").display = display.hidden;

      this.getField("deep_diver").display = display.hidden;

      this.getField("JOINT AS_MC").display = display.hidden;

      this.getField("JOINT AS_DD").display = display.hidden;

      this.getField("JOINT DD_MC").display = display.hidden;

      this.getField("no_score").display = display.visible;

      }

       

      Thanks in advance

        • 1. Re: What have I done wrong with this IF statement?
          Test Screen Name Most Valuable Participant

          Ah, this is an easy one because we've all done this, over and over...

           

          if ( nResult = 200 )

           

          Means something but not at all what you think. The test for equality is not one equals sign but two.

           

          if ( nResult == 200 )

           

          and throughout.

          1 person found this helpful
          • 2. Re: What have I done wrong with this IF statement?
            soulglowdeej Level 1

            wooo hoooo!!! Thanks Test Screen Name! I can breathe again

            • 3. Re: What have I done wrong with this IF statement?
              gkaiseril MVP & Adobe Community Professional

              You could also set the display to all the fields to hidden and then only switch the needed field to visible for a given score. JavaScript also has the "switch" statement so one does not need to use the nested if statement.

               

              this.getField("adventure_seeker").display = display.hidden;
              this.getField("mountain_climber").display = display.hidden;
              this.getField("deep_diver").display = display.visible;
              this.getField("JOINT AS_MC").display = display.hidden;
              this.getField("JOINT AS_DD").display = display.hidden;
              this.getField("JOINT DD_MC").display = display.hidden;
              this.getField("no_score").display = display.hidden;

              switch(this.getField("score").valueAsString)
              {
              case "200":
              this.getField("deep_diver").display = display.visible;
              break;

              case "160":
              case "151":
              this.getField("deep_diver").display = display.visible;
              break
              case "40":
              case "31":
              case "80":
              case "71":
              this.getField("adventure_seeker").display = display.visible;
              break;
              case "4":
              case "13":
              case "53":
              case "62":
              this.getField("mountain_climber").display = display.visible;
              break;
              case "22":
              this.getField("JOINT AS_MC").display = display.visible;
              case "102":
              this.getField("JOINT AS_DD").display = display.visible;
              break;
              case "120":
              this.getField("JOINT DD_MC").display = display.visible;
              break;
              default:
              this.getField("no_score").display = display.visible;
              break;
              } // end switch score;

               

              This cuts down on the number of lines to code by starting with a known state and changing the minimum of fields and uses a compound case statement to reduce the amount of redundant code. This could also be done with the "if" statement by using a complex logical statement use the logical OR operator.

              1 person found this helpful
              • 4. Re: What have I done wrong with this IF statement?
                soulglowdeej Level 1

                Hi gkaiseril,

                 

                I think I understand this approach - thanks for the info!