The Hourglass Pattern
MediumAcc. 87.6%
+30 XP 12
Temporal Symmetry
An hourglass consists of a full downward triangle followed by a full upward triangle, sharing a single-star center.
The Assignment
Your function receives width (must be odd).
- First block: Draw downward triangle (from
widthstars down to 1). - Second block: Draw upward triangle (from 3 stars up to
width). - Correct leading spaces for every row to center the stars.
01EXAMPLE 1
Input
width = 3Output
***
*
***Explanation: The 3x3 hourglass.
Constraints
- Must handle leading spaces correctly.
- Assume width is odd.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
width3
Expected Output
*** * ***
Click RUN to test your solution