Timkor

firTreeOneLoop

Sep 24th, 2020
1,015
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let heigh = +prompt('Type any number')
  2. //let allStarNum = heigh * (1 + (heigh * 2 - 1)) / 2; // complex evaluate
  3. let allStarNum = heigh**2; //simple evaluate, cause the tree has an area of a square
  4.  
  5. for(let strNum = 0, starsNum = 1, spacesNum = (heigh * 2 - 1);
  6.  strNum < heigh + 1; strNum++, starsNum += 2, spacesNum -= 1){
  7.      if (strNum === heigh ){  //test for penechek
  8.          starsNum = 1;
  9.          spacesNum = heigh * 2 - 1;
  10.      }
  11.     console.log(' '.repeat(spacesNum) + '*'.repeat( starsNum) + ' '.repeat(spacesNum) +
  12.       '" "=' + spacesNum + ' *=' + starsNum);
  13. }
RAW Paste Data