Skip to content

Instantly share code, notes, and snippets.

@richietyler
Created October 28, 2022 00:18
Show Gist options
  • Save richietyler/896c05aef771ea62972c2d1dfbfb604b to your computer and use it in GitHub Desktop.
Save richietyler/896c05aef771ea62972c2d1dfbfb604b to your computer and use it in GitHub Desktop.
Simple function to convert Canadian province/territory codes to names
function caProvinceCodesToNames(stateCode) {
const code = stateCode.toLowerCase();
if (code === "ab") {
return "Alberta"
} else if (code === "bc") {
return "British Columbia"
} else if (code === "mb") {
return "Manitoba"
} else if (code === "nb") {
return "New Brunswick"
} else if (code === "nl") {
return "Newfoundland and Labrador"
} else if (code === "ns") {
return "Nova Scotia"
} else if (code === "on") {
return "Ontario"
} else if (code === "pe") {
return "Prince Edward Island"
} else if (code === "qc") {
return "Quebec"
} else if (code === "sk") {
return "Saskatchewan"
} else if (code === "nt") {
return "Northwest Territories"
} else if (code === "nu") {
return "Nunavut"
} else if (code === "yt") {
return "Yukon"
} else {
return "You haven't entered a valid CA province or territory code"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment