Didart

Building - Nested Loops

Apr 19th, 2022
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function building(input) {
  2.     let floor = Number(input[0]);
  3.     let room = Number(input[1]);
  4.  
  5.     for (let a = floor; a > 0; a--) {
  6.         let buffer = "";
  7.         for (let b = 0; b < room; b++) {
  8.  
  9.             if (a === floor) {
  10.                 buffer += "L" + a + b + " ";
  11.             } else if (a % 2 === 0) {
  12.                 buffer += "O" + a + b + " ";
  13.             } else {
  14.                 buffer += "A" + a + b + " ";
  15.             }
  16.         }
  17.         console.log(buffer);
  18.     }
  19.  
  20. }
  21.  
  22. building(["6", "4"])
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment