Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Drawing ***** in square
- function makeAsterix(asterix, char){
- return asterix + ' ' + char;
- }
- function makeSquareForMe(maxColumns, maxRows){
- var asterix = '';
- for(var i = 0; i < maxRows; i++){
- 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)
- if(i == 0 || i == maxRows - 1){ // || is OR operator - either i==0 OR i==5 should be true
- asterix = makeAsterix(asterix,'*');
- }else{
- if(j == 0 || j == maxColumns - 1){ // i is for rows, j is for columns (nested loops)
- asterix = makeAsterix(asterix,'*');
- }else{
- asterix = makeAsterix(asterix,' ');; // add 2 spaces to match previous IF caracter size (2 chars)
- }
- }
- }
- asterix += '\n' // \n breaks the line
- }
- console.log(asterix);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement