Last active
August 29, 2015 14:24
-
-
Save alexeyraspopov/3f9a9b4eff755186ee4e to your computer and use it in GitHub Desktop.
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
// https://developer.mozilla.org/ru/docs/Web/API/ValidityState | |
var validityState = { valid: false, stepMismatch: true, tooLong: false }; | |
function errorMessage(validity) { | |
// Constant goes in expression | |
switch (true) { | |
// Variable goes in a case clause | |
case !validity.valid: | |
return 'is not a Number'; | |
case validity.stepMismatch: | |
return 'value does not fit the rules determined by the step attribute'; | |
case validity.tooLong: | |
return 'value does not need to be longer than ...'; | |
default: | |
return 'some error occurred'; | |
} | |
} | |
console.log(errorMessage(validityState)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment