ProdanTenev

Pyramid Nums

Mar 6th, 2022
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.55 KB | None | 0 0
  1. function pyramidNums(input) {
  2.     let num = Number(input[0]);
  3.     let currentNum = 1;
  4.     let isBigger = false;
  5.     let printLine = "";
  6.     for (let rows = 1; rows <= num; rows++) {
  7.         for (let columns = 1; columns <= rows; columns++) {
  8.             if (currentNum > num) {
  9.                 isBigger = true;
  10.                 break;
  11.             }
  12.             printLine += currentNum + " ";
  13.             currentNum++;
  14.         }
  15.         console.log(printLine);
  16.         printLine = "";
  17.         if (isBigger) {
  18.             break;
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment