Just used some for loops to print all of the asterisks, after doing a check for over 0 and odd, and added some css to make the shape of a diamond.
Codepen
const stringDiamond = rows => { if (rows > 0 && rows % 2 === 1) { let diamond = ""; for(let i = 1; i< rows + 1; i += 2) { diamond += "<p>"; for(let j = 1; j < i + 1; j++) { diamond += "*"; } diamond += "</p>"; } for(let i = rows - 2; i> 0; i-=2) { diamond += "<p>"; for(let j = 1; j < i + 1; j++) { diamond += "*"; } diamond += "</p>"; } return diamond; } else { return "null" } }
The CSS making the asterisks look like a diamond
#answer { text-align: center; line-height: 5px; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just used some for loops to print all of the asterisks, after doing a check for over 0 and odd, and added some css to make the shape of a diamond.
Codepen
The CSS making the asterisks look like a diamond