Skip to content

Instantly share code, notes, and snippets.

@ChandraNalaani
Created May 31, 2012 18:16
Show Gist options
  • Save ChandraNalaani/2845174 to your computer and use it in GitHub Desktop.
Save ChandraNalaani/2845174 to your computer and use it in GitHub Desktop.
Health suggestions in a multilevel conditional (javascript)
// multilevel conditional - switch/case statement
window.onload = initAll;
function initAll() {
document.getElementById("Mental").onclick
= health;
document.getElementById("Physical").onclick
= health;
document.getElementById("Spiritual").onclick
= health;
}
function health() {
switch(this.id) {
case "Mental":
alert("Play Sudoku");
break;
case "Physical":
alert("Do yoga");
break;
case "Spiritual":
alert("Meditate");
break;
default:
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment