Last active
February 4, 2022 09:21
-
-
Save richietyler/971b531091df06a9ced652d7a654c92e to your computer and use it in GitHub Desktop.
USA State codes to State Names function
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
// Simple function to convert US 2-letter state codes to capitalised state names | |
function usStateCodesToNames(stateCode) { | |
const code = stateCode.toLowerCase(); | |
if (code === "al") { | |
return "Alabama" | |
} else if (code === "ak") { | |
return "Alaska" | |
} else if (code === "az") { | |
return "Arizona" | |
} else if (code === "ar") { | |
return "Arkansas" | |
} else if (code === "ca") { | |
return "California" | |
} else if (code === "co") { | |
return "Colorado" | |
} else if (code === "ct") { | |
return "Connecticut" | |
} else if (code === "de") { | |
return "Delaware" | |
} else if (code === "dc") { | |
return "District of Columbia" | |
} else if (code === "fl") { | |
return "Florida" | |
} else if (code === "ga") { | |
return "Georgia" | |
} else if (code === "hi") { | |
return "Hawaii" | |
} else if (code === "id") { | |
return "Idaho" | |
} else if (code === "il") { | |
return "Illinois" | |
} else if (code === "in") { | |
return "Indiana" | |
} else if (code === "ia") { | |
return "Iowa" | |
} else if (code === "ks") { | |
return "Kansas" | |
} else if (code === "ky") { | |
return "Kentucky" | |
} else if (code === "la") { | |
return "Louisiana" | |
} else if (code === "me") { | |
return "Maine" | |
} else if (code === "md") { | |
return "Maryland" | |
} else if (code === "ma") { | |
return "Massachusetts" | |
} else if (code === "mi") { | |
return "Michigan" | |
} else if (code === "mn") { | |
return "Minnesota" | |
} else if (code === "ms") { | |
return "Mississippi" | |
} else if (code === "mo") { | |
return "Missouri" | |
} else if (code === "mt") { | |
return "Montana" | |
} else if (code === "ne") { | |
return "Nebraska" | |
} else if (code === "nv") { | |
return "Nevada" | |
} else if (code === "nh") { | |
return "New Hampshire" | |
} else if (code === "nj") { | |
return "New Jersey" | |
} else if (code === "nm") { | |
return "New Mexico" | |
} else if (code === "ny") { | |
return "New York" | |
} else if (code === "nc") { | |
return "North Carolina" | |
} else if (code === "nd") { | |
return "North Dakota" | |
} else if (code === "oh") { | |
return "Ohio" | |
} else if (code === "ok") { | |
return "Oklahoma" | |
} else if (code === "or") { | |
return "Oregon" | |
} else if (code === "pa") { | |
return "Pennsylvania" | |
} else if (code === "ri") { | |
return "Rhode Island" | |
} else if (code === "sc") { | |
return "South Carolina" | |
} else if (code === "sd") { | |
return "South Dakota" | |
} else if (code === "tn") { | |
return "Tennessee" | |
} else if (code === "tx") { | |
return "Texas" | |
} else if (code === "ut") { | |
return "Utah" | |
} else if (code === "vt") { | |
return "Vermont" | |
} else if (code === "va") { | |
return "Virginia" | |
} else if (code === "wa") { | |
return "Washington" | |
} else if (code === "wv") { | |
return "West Virginia" | |
} else if (code === "wi") { | |
return "Wisconsin" | |
} else if (code === "wy") { | |
return "Wyoming" | |
} else { | |
return "You've entered an invalid state code" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment