...

View Full Version : Shorten conditions



florida
10-27-2003, 06:36 PM
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:



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:




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
}

sciguyryan
10-27-2003, 06:59 PM
Try using the Javascript conditional statement that goes like this: condition ? expresionIfTrue : expresionIfFalse

If you use that it should significantly shorten your script.

Danne
10-27-2003, 08:45 PM
Maybe if you reomve the red:


if((this.ID >= 3) && (this.ID <= 7 ))
{
layerHeader += ' + (this.y - 16) + ';">';
}
else if((this.ID >= 8) && (this.ID <= 11 ))
{
layerHeader += ' + (this.y - 20) + ';">';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum