Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Drawing ***** in square
  2. function makeAsterix(asterix, char){
  3.     return asterix + ' ' + char;
  4. }
  5.  
  6. function makeSquareForMe(maxColumns, maxRows){
  7. var asterix = '';
  8. for(var i = 0; i < maxRows; i++){
  9.     for(j = 0; j < maxColumns; j++){ // this nested loop repeats 6 times, so each parent loop will also repeat 6 times (=> 36 *s as result)
  10.         if(i == 0 || i == maxRows - 1){   // || is OR operator - either i==0 OR i==5 should be true
  11.             asterix = makeAsterix(asterix,'*');
  12.         }else{
  13.             if(j == 0 || j == maxColumns - 1){   // i is for rows, j is for columns (nested loops)
  14.                 asterix = makeAsterix(asterix,'*');
  15.             }else{
  16.                 asterix = makeAsterix(asterix,' ');; // add 2 spaces to match previous IF caracter size (2 chars)
  17.             }
  18.         }
  19.     }
  20.     asterix += '\n' // \n breaks the line
  21. }
  22. console.log(asterix);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement