Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Shorten conditions

    I have conditions that work but was hoping to shorten it in the "layerheader" part where I could "cut" it up.
    This is current condtions that work:

    Code:
    if (condition here)
    {
       if((this.ID >= 3) && (this.ID <= 7 ))
       { 
          layerHeader = '<div id=menu' + this.ID + ' style="background: ; width: ' + this.width + '; visibility: hidden; position: absolute; left: ' + this.x +  '; top: ' +  (this.y - 16) + ';">';
       }
       else if((this.ID >= 8) && (this.ID <= 11 ))
       { 
           layerHeader = '<div id=menu' + this.ID + ' style="background: ; width: ' + this.width + '; visibility: hidden; position: absolute; left: ' + this.x +  '; top: ' +  (this.y - 20) + ';">';
       }
    //alot more else ifs continue here
    }

    My attempt to shorten and concatenate the condition here not working:

    Code:
    if (condition here)
    {
    layerHeader = '<div id=menu' + this.ID + ' style="background: ; width: ' + this.width + '; visibility: hidden; position: absolute; left: ' + this.x +  '; top: ';
                                                     
       if((this.ID >= 3) && (this.ID <= 7 ))
       { 
          layerHeader += ' +  (this.y - 16) + ';">';
       }
       else if((this.ID >= 8) && (this.ID <= 11 ))
       { 
          layerHeader += ' +  (this.y - 20) + ';">';
       }
       //alot more else ifs continue here
    }

  • #2
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try using the Javascript conditional statement that goes like this: condition ? expresionIfTrue : expresionIfFalse

    If you use that it should significantly shorten your script.
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe if you reomve the red:
    Code:
       if((this.ID >= 3) && (this.ID <= 7 ))
       { 
          layerHeader += ' +  (this.y - 16) + ';">';
       }
       else if((this.ID >= 8) && (this.ID <= 11 ))
       { 
          layerHeader += ' +  (this.y - 20) + ';">';
       }
    /Daniel


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •