How to print text diagonally from left to right in JavaScript

1 Answer

0 votes
function printDiagonalTextLTR(text) {
    for (let i = 0; i < text.length; i++) {
        console.log(" ".repeat(i) + text[i]);
    }
}

printDiagonalTextLTR("HELLO WORLD");


/*
run:

H
 E
  L
   L
    O
      
      W
       O
        R
         L
          D

*/

 



answered Apr 8 by avibootz
...