Quick question: is this kind of nesting possible?
An if statement first passing a switch and then another if statement so it won’t affect other values that were not caught on switch?
var cookie = ""; //some value previously setted by filtering a cookie, like a product id
var prod = "";
var img = "";
if ((cookie != null) && (prod != '')) {
switch (cookie) {
case '001': case '002': case '003':
prod = "Product01";
img = "product01.jpg"
break;
case '004': case '005': case '006':
prod = "Product02";
img = "product02.jpg"
break;
case '007': case '008':
prod = "Product03";
img = "product03.jpg"
break;
case 'null':
break;
}
if (window.location.pathname == 'somepage') {
//jQuery code
} else if (window.location.pathname == 'anotherpage') {
//jQuery code
} else {
//jQuery code
}
}
Yes it is.
You can write something like
and also
..well I’m not going to show all the cases…
Just have a look here http://www.w3schools.com/js/js_switch.asp and here http://www.w3schools.com/js/js_if_else.asp you’ll find more details also about the else statement. And as somebody sad in the comments: try it!
Often it’s the best way to understand.