Skip to content

Instantly share code, notes, and snippets.

@mrandyclark
Created October 17, 2011 18:01
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/1293303 to your computer and use it in GitHub Desktop.
Save mrandyclark/1293303 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 = "";
if(messageCode == 1)
errorMessage = "Your username could not be found."
} else if(messageCode == 2) {
errorMessage = "Your password is incorrect."
} else if(messageCode == 3) {
errorMessage = "You are just an idiot."
}
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