Skip to content

Instantly share code, notes, and snippets.

@alexeyraspopov
Last active August 29, 2015 14:24
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 alexeyraspopov/3f9a9b4eff755186ee4e to your computer and use it in GitHub Desktop.
Save alexeyraspopov/3f9a9b4eff755186ee4e to your computer and use it in GitHub Desktop.
// 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