Created
June 6, 2020 18:22
-
-
Save Kielx/ed3671920d3a563764d324f4231f0b7b to your computer and use it in GitHub Desktop.
evenDigitsOnly scrimba coding challange
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
//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