Skip to content

Instantly share code, notes, and snippets.

@Kielx
Created June 6, 2020 18:22
Show Gist options
  • Save Kielx/ed3671920d3a563764d324f4231f0b7b to your computer and use it in GitHub Desktop.
Save Kielx/ed3671920d3a563764d324f4231f0b7b to your computer and use it in GitHub Desktop.
evenDigitsOnly scrimba coding challange
//function checkIfEven checks if given number consists of only even digits
const checkIfEvenDigit = function (number) {
if (number % 2 === 0) {
return true;
} else {
return false;
}
};
function checkIfEvenNumber(number) {
const numberString = [...number.toString(10)];
for (let i = 0; i < numberString.length; i++) {
if (!checkIfEvenDigit(numberString[i])) {
return false;
}
}
return true;
}
console.log(checkIfEvenDigit(3));
console.log(checkIfEvenNumber(442));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment