Skip to content

Commit 8303039

Browse files
committed
console.log test done
1 parent 1d07973 commit 8303039

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function cardValidator(num) {
2+
const numStr = num.toString(); // Convert to string for iteration
3+
if (numStr.length !== 16 || !/^[0-9]+$/.test(numStr) || numStr[numStr.length -1] % 2 === 1) {
4+
return false; // Check length is 16 numbers long, if it only contains digits and if the last digits is even
5+
}
6+
7+
let firstDigit = numStr[0]; // Track the first digit
8+
for (let i = 1; i < numStr.length; i++) {
9+
if (numStr[i] !== firstDigit) {
10+
return true; // Found at least two different digits
11+
}
12+
}
13+
14+
return false; // All digits are the same
15+
}
16+
17+
console.log(cardValidator(1111111111111111)); // Output: false
18+
console.log(cardValidator(1234567890123456)); // Output: true
19+
console.log(cardValidator(2222222222222222)); // Output: false
20+
console.log(cardValidator(3333333333333334)); // Output: true
21+

0 commit comments

Comments
 (0)