The X-Factor Grid

MediumAcc. 85.2%
+30 XP 12

Crossing Paths

An X-pattern occurs when symbols are placed on the two main diagonals of a square. Diagonal 1: $i = j$ Diagonal 2: $i + j = size - 1$

The Assignment

Your function receives a parameter size.

  1. Use nested loops to iterate through a size x size grid.
  2. If the cell is on either diagonal, print *.
  3. Otherwise, print a space.
  4. Ensure each row is printed on a new line.

01EXAMPLE 1

Inputsize = 3
Output* * * * *

Explanation: The 3x3 diagonal cross.

Constraints

  • Ensure the formula i+j === size-1 is used.
  • Handle even and odd sizes.
MathLoopsPatterns
JavaScript
Loading...
2 Hidden

Input Arguments

size3

Expected Output

* *
 * 
* *

Click RUN to test your solution