Carlos13
06-21-2012, 12:08 AM
Hi,
I am new to javascript and have the following dilemma. I will give you a short example and if you need any more information just ask. I have various different variables (about 16) if one of the variables is greater than or equal to one I what it to show a <div>. This works fine however there is going to be so many if and else if statements and wondering if there was an easier way of doing this.
Here is an example of how it would work.
function() {
if (Variable1 >= 1) {
show div1
if (Variable2 >= 1) {
show div2
}
}
else if (Variable2 >= 1) {
show div2
}
}
So in this example whether Variable1 is true or not it would still need to check Variable2.
This is fine for a few Variables but when I have 16 this is going to get very messy and hard to read if I keep doing nested if statements and then else if statements. Is there another (Better cleaner way) to do this. I have looked at tutorials but can't seem to work out a way. I know I am new to this so if the solution is easy I can only apologise. I would really appreciate any reply.
I am new to javascript and have the following dilemma. I will give you a short example and if you need any more information just ask. I have various different variables (about 16) if one of the variables is greater than or equal to one I what it to show a <div>. This works fine however there is going to be so many if and else if statements and wondering if there was an easier way of doing this.
Here is an example of how it would work.
function() {
if (Variable1 >= 1) {
show div1
if (Variable2 >= 1) {
show div2
}
}
else if (Variable2 >= 1) {
show div2
}
}
So in this example whether Variable1 is true or not it would still need to check Variable2.
This is fine for a few Variables but when I have 16 this is going to get very messy and hard to read if I keep doing nested if statements and then else if statements. Is there another (Better cleaner way) to do this. I have looked at tutorials but can't seem to work out a way. I know I am new to this so if the solution is easy I can only apologise. I would really appreciate any reply.