Write a function isValidCard(number). number is 16 digits as text. Check it with the Luhn method: from the RIGHT, double every SECOND digit (the 2nd, 4th ...), subtract 9 from any doubled value over 9, and add everything up. The number is valid if it has 16 digits and the total divides by 10. Give back true or false. (Made-up test numbers only.)
You will practice: check digits, Luhn method, validation
Press Tab to indent. Press Esc and then Tab to move on to the next button.
Your code runs in your browser. We do not receive it or save it.
Test results
What your code printed
CC BY-SA 4.0
Adapted from a CS Unplugged programming challenge by the University of Canterbury Computer Science Education Research Group, licensed CC BY-SA 4.0.
Changes: Rewritten in our own words as a function with tests, hints and steps, in Python and JavaScript, by Open Cosmos. This version is also CC BY-SA 4.0.
Accessibility settings
Change how Open Cosmos looks and moves. Your choices are saved only in this browser.