1 Reply Latest reply on Jun 21, 2013 6:36 AM by AMULI

    Javascript coding issues (if else statements)

    Mike Dubbzz

      Hello to all,

       

      I am posting for help for problems I am having with javascript. The website is www.goshowpro.com. Right now on the website it is connected by multiple html files but I would like to have it all on one single page with the animations responding. I would like the animation to be seamless but I am relatively new to javascript and am having issues with my syntax I believe. Below is the code for my new home page/index button. Thank you for your help in advance. 

       

      -Michael  

      ------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------

      if (mymovie == "hporstop"){

      // play the timeline from the given position (ms or label)

      sym.play("phomstart");

      }

      else if (mymovie == "por1.1stop"){

      // play the timeline from the given position (ms or label)

      sym.play("phomstart");

      }

      else if (mymovie == "por1.2stop"){

      // play the timeline from the given position (ms or label)

      sym.play("phomstart");

      }

      else if (mymovie == "por1.3stop"){

      // play the timeline from the given position (ms or label)

      sym.play("phomstart");

      }

      else if (mymovie == "sporstop"){

      // play the timeline from the given position (ms or label)

      sym.play("phomstart");

      }

      else if (mymovie == "cporstop"){

      // play the timeline from the given position (ms or label)

      sym.play("phomstart");

      }

      else if (mymovie == "hconstop"){

      // play the timeline from the given position (ms or label)

      sym.play("chomstart");

      }

      else if (mymovie == "sconstop"){

      // play the timeline from the given position (ms or label)

      sym.play("chomstart");

      }

      else if (mymovie == "pconstop"){

      // play the timeline from the given position (ms or label)

      sym.play("chomstart");

      }

      else if (mymovie == "cserstop"){

      // play the timeline from the given position (ms or label)

      sym.play("shomstart");

      }

      else if (mymovie == "hserstop"){

      // play the timeline from the given position (ms or label)

      sym.play("shomstart");

      }

      else (mymovie == "pserstop"){

      // play the timeline from the given position (ms or label)

      sym.play("shomstart");

      }

        • 1. Re: Javascript coding issues (if else statements)
          AMULI Level 4

          Hi Mike,

           

          When you test the different possible values of a variable mymovie, you are better off using a switch.

           

          See : http://www.w3schools.com/js/js_switch.asp

           

          Then you could avoid repeating statements by regrouping cases :

           

          switch( mymovie)

          {

            case "hporstop":

            case "por1.1stop":

            case "por1.2stop":

            case "por1.3stop":

            case "sporstop":

            case "cporstop":

               sym.play("phomstart");

               break;

            case "hconstop":

            case "sconstop":

            case "pconstop":

               sym.play("chomstart");

               break;

            case "cserstop":

            case "hserstop":

            case "pserstop":

               sym.play("shomstart");

               break;

          }


          What is important to grasp to understand the flow of execution is that the break; statement prevents from testing the following cases.

           

          Gil