Skip to content

Instantly share code, notes, and snippets.

@mrandyclark
Created October 17, 2011 17:58
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 mrandyclark/1293286 to your computer and use it in GitHub Desktop.
Save mrandyclark/1293286 to your computer and use it in GitHub Desktop.
<script>
// this is a function that you're going to pass a messageCode to.
// the message code will be an integer and you'll return a string
// that is the error message.
function getErrorMessage(messageCode)
{
var errorMessage = "";
// start the switch statement
switch(messageCode)
{
case 1:
errorMessage = "Your username could not be found."
break;
case 2:
errorMessage = "Your password is incorrect."
break;
case 3:
errorMessage = "You are just an idiot."
break;
}
return errorMessage;
}
// writes the 1st error message
document.write( getErrorMessage(1) );
// writes the 2nd error message
document.write( getErrorMessage(2) );
// writes the 3rd error message
document.write( getErrorMessage(3) );
// writes no error message
document.write( getErrorMessage(4) );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment