Home My space log
Language EN (English)

Check any barcode

JavaScript Advanced astronaut ages teen+ From CS Unplugged

The problem

Barcodes can have 8, 12 or 13 digits. Write a function isValidBarcode(code) that checks any of them. Start from the RIGHT: the last digit counts once, the next one three times, then once, then three times, and so on. The code is valid if the total divides by 10. Give back true or false.

You will practice: check digits, loops from the right, validation

Mode

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.

      Original challenge · License: 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.