Menu
Coddy logo textTech

Number Pyramid

Part of the Fundamentals section of Coddy's JavaScript journey — lesson 75 of 77.

Arithmetic operations can also be done on strings. For example:

let str1 = "aaa" + "b";

str1 will hold "aaab"

This is the same as:

let str1 = "aaa";
str1 += "b";

Also, we can even use multiplications with repeat():

let str1 = "a".repeat(10);

str1 will hold "aaaaaaaaaa"

challenge icon

Challenge

Easy

Each test case has one input - an odd whole number. (given)
Your task is to print n - pyramid using *, here are some examples:

1 - pyramid

*

5 - pyramid

*
***
*****

7 - pyramid

*
***
*****
*******

Input

  • odd integer n from user
  • 1 <= n < 1000

Tips

  • Try starting from the small triangles
  • Check the hint if you are stuck ;)

n represents the number of  * in the bottom row

Cheat sheet

String concatenation using the + operator:

let str1 = "aaa" + "b"; // "aaab"

String concatenation using the += operator:

let str1 = "aaa";
str1 += "b"; // "aaab"

String repetition using repeat():

let str1 = "a".repeat(10); // "aaaaaaaaaa"

Try it yourself

let n = parseInt(inp); // Don't change this line
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals