Last active
August 29, 2015 14:14
-
-
Save appkr/912dce004e4c0f4984d9 to your computer and use it in GitHub Desktop.
JavaScript Switch Block// source http://jsbin.com/yeduyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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