Home My space log
Language EN (English)

Cards from the biggest down

JavaScript Beginner robot ages 8-10 From CS Unplugged

The problem

Write a function cardsFromLargest(largest). It gives back the binary card values from largest down to 1. Example: 8 gives [8, 4, 2, 1]. You can trust that largest is 1, 2, 4, 8, 16 and so on.

You will practice: lists, while loops, halving

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.