FlipFlop (Super Edition)
The Big Idea
You will write a function that takes a number and returns "Flip", "Flop", "FlipFlop", or the number itself — based on divisibility rules. Then you will write a second function that applies the first to an entire array. This challenge requires you to pseudocode your approach before writing any code.
Your Roadmap
| Section | Time | Required? |
|---|---|---|
| The challenge | 15 min | ⚑ Required |
| Plan your code | 20 min | ⚑ Required |
| Write and test | 3.5 hrs | ⚑ Required |
The challenge
Write a function called flipflop that takes a number and returns:
"FlipFlop"if the number is divisible by both 3 and 5"Flop"if divisible by 5 only"Flip"if divisible by 3 only- The number itself if none of the above apply
flipflop(3) // "Flip"flipflop(5) // "Flop"flipflop(15) // "FlipFlop"flipflop(7) // 7
Then write a function called superFlipFlop that takes an array of numbers and returns a new array with the FlipFlop rules applied to each element:
superFlipFlop([1, 2, 3]) // [1, 2, "Flip"]superFlipFlop([1, 2, 5]) // [1, 2, "Flop"]superFlipFlop([1, 2, 15]) // [1, 2, "FlipFlop"]superFlipFlop([30, 9, 20, 1]) // ["FlipFlop", "Flip", "Flop", 1]
Key tool: The remainder operator (%) tells you if a number divides evenly:
if (i % 3 === 0) // true if i is divisible by 3
Plan your code
Before writing any code, write pseudocode comments describing your steps.
Write your plan in plain English as comments in your file. For example:
// check if the number is divisible by both 3 and 5// if yes, return "FlipFlop"// ...
Your pseudocode does not need to be perfect. It is a first draft — you will change it as you go. The point is to think before you type.
Write and test
Run the tests:
npm test 3-super-flipflop
Write your initial solution to match your pseudocode. Run the tests. If they pass, move on. If not, read the error messages and adjust.