Created
October 17, 2011 17:58
-
-
Save mrandyclark/1293286 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<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