Skip to content

Instantly share code, notes, and snippets.

@appkr
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appkr/912dce004e4c0f4984d9 to your computer and use it in GitHub Desktop.
Save appkr/912dce004e4c0f4984d9 to your computer and use it in GitHub Desktop.
JavaScript Switch Block// source http://jsbin.com/yeduyi
function Knight(name, regiment) {
this.name = name;
this.regiment = regiment;
switch(regiment) {
case 1:
this.weapon = "Broadsword";
break;
case 2:
this.weapon = "Claymore";
break;
default:
this.weapon = "WoodSword";
}
}
function ceremonialDagger(knight, rank) {
this.length = 8;
this.owner = knight;
switch(rank) {
case "King": this.diamonds = 1;
case "High Constable": this.amethyst = 2;
case "Field Marshal": this.saphires = 4;
case "Captain": this.emeralds =1;
case "Knight": this.rubies = 6;
}
}
var solder = new Knight("Richard", 2);
console.log(solder.weapon);
var knightDagger = new ceremonialDagger("Jerome", "Knight");
console.log(knightDagger);
var marshalsDagger = new ceremonialDagger("Timothy", "Field Marshal");
console.log(marshalsDagger);
var kingsDagger = new ceremonialDagger("Arthur", "King");
console.log(kingsDagger);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment