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
EasyEach 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
nfrom user - 1 <=
n< 1000
Tips
- Try starting from the small triangles
- Check the hint if you are stuck ;)
nrepresents 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 lineThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Type Coercion7Bill Split Calculator
Welcome MessageCalculating The Tip And Total2Variables
NumbersStringBooleanNaming ConventionsEmpty VariablesRecap - Initialize VariablesConstants3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsStrict vs Loose EqualityRecap - Simple Math6Basic IO
OutputOutput with VariablesType Conversion - Part 1Type Conversion - Part 2Recap - Till 120Recap - True or False