How to print the alphabets in left right right left pattern with JavaScript

1 Answer

0 votes
const rows = 13;
let line_number = 1;
      
if (rows <= 13 && rows >=1) {
   for (let i = 1; i <= rows * 2; i += 2) {
        if (line_number % 2 == 1) {
            console.log(String.fromCharCode(i + 64) + " " + String.fromCharCode(i + 65));
        } else {
            console.log(String.fromCharCode(i + 65) + " " + String.fromCharCode(i + 64));
        }
        line_number++;
   }
}   

  
    
    
/*
run:
    
"A B"
"D C"
"E F"
"H G"
"I J"
"L K"
"M N"
"P O"
"Q R"
"T S"
"U V"
"X W"
"Y Z"
    
*/

  

 



answered Sep 25, 2021 by avibootz
...