Skip to content

Instantly share code, notes, and snippets.

@beatrizsmerino
Last active March 13, 2023 23:46
Show Gist options
  • Save beatrizsmerino/0fb7e1e69e14a2cf796e8e3bc8c97b0b to your computer and use it in GitHub Desktop.
Save beatrizsmerino/0fb7e1e69e14a2cf796e8e3bc8c97b0b to your computer and use it in GitHub Desktop.
Verify if it is a number
function validation(num) {
if (num == "undefined" || num == null || num == "") {
console.log("Inserta un número.");
return 0;
} else {
if (isNaN(num) && num !== "") {
console.log("Ups... " + "'" + + num + "'" + " no es un número.");
return 1;
} else {
if (num % 1 == 0) {
console.log("'" + num + "'" + " es un numero entero.");
return 2;
} else {
console.log("'" + num + "'" + " es un numero decimal.");
return 3;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment