← Back to challenges

Roll the Dice

JavaScriptHardnumbersloops

Instructions

Dice eyes

Write a function that returns the dice with the correct amount of eyes in a single string.

6 can be written as:

O-O
O-O
O-O

Or:

O-O/O-O/O-O  // with slashes and dashes

And 1:

---/-O-/---

Your function will have to return the dice as shown in the image. Look at the examples and the Tests tab what is asked. Multiple dice are separated by a comma and space.

Examples

dice(3) ➞ "O--/-O-/--O"

dice(8) ➞ "O-O/O-O/O-O, O--/---/--O"

dice(6) ➞ "O-O/O-O/O-O"

Notes

The input is always a positive number, return an empty string when 0 is given.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.