Skip to content

Instantly share code, notes, and snippets.

@dustintheweb
Last active August 29, 2015 13:57
Show Gist options
  • Save dustintheweb/9759217 to your computer and use it in GitHub Desktop.
Save dustintheweb/9759217 to your computer and use it in GitHub Desktop.
Switch Statement Example / Syntax
var yourFunction = function(id) {
var _somePath,
_img,
conditionA = !! (window.someGlobalVar === 5), // if you need internal ternary conditions (path switching for example)
conditionB = !! (window.someGlobalVar === 10),
conditionC = !! (window.someGlobalVar === 15);
switch (id) {
case 'some-id-name-1':
// do something
_somePath = (conditionA) ? '/media/big-1.jpg' : (conditionB) ? '/media/med-1.jpg' : '/media/lil-1.jpg';
break;
case 'some-id-name-2':
_somePath = (conditionA) ? '/media/big-2.jpg' : (conditionB) ? '/media/med-2.jpg' : '/media/lil-2.jpg';
break;
case 'some-id-name-3':
_somePath = (conditionA) ? '/media/big-3.jpg' : (conditionB) ? '/media/med-3.jpg' : '/media/lil-3.jpg';
break;
}
_img = <img src="'+ _somePath +'">
$('#' + id).append(_img);
}
yourFunction(itemID);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment