13 Replies Latest reply on Oct 11, 2014 1:13 AM by pravaut

    help with if else statment and math.random

    pravaut Level 1

      hi kinda of new to js and need to populate a text field with text picked at random from an array when a button pressed based on what is put in another text field wich is also done at random.

      i really hope that makes sence but here is code i got so far

       

      var bg = this.getField("Background").valueAsString;

       

       

      var pt_sage = new array();

        pt_sage[0] = "some text based on background";

        pt_Sage[1] = "some more text based on background";

      var i = Math.floor(2*Math.random())

       

       

      var pt_hermit = new array();

        pt_hermit[0] = "some text"

        pt_hermit[1] = "some more text"

      var v = Math.floor(2*Math.random())

       

       

      if (bg == "Sage") {

        this.getField("PersonalityTraits").value = pt_Sage[i];

      } else (bg == "Hermit"){

        this.getField("PersonalityTraits").value = pt_hermit[v];

        }

       

       

       

      hope some one can help and thanks in advanced