Source Code
function printStarPattern(character) { const patterns = { 'R': [ '*****', '* *', '*****', '* *', '* *', ], 'A': [ ' * ', ' * * ', '* *', ' *****', ' * *', ], 'M': [ '* *', '** **', '* * *', '* *', '* *', ], }; if (patterns[character]) { return patterns[character]; } else { console.log('Pattern not defined for character: ' + character); return []; } } function printRAM() { const word = ['R', 'A', 'M']; for (let row = 0; row < 5; row++) { let line = ''; for (let i = 0; i < word.length; i++) { const patternLines = printStarPattern(word[i]); line += patternLines[row] + ' '; } console.log(line); } } // Call the function to print "RAM" side by side printRAM();
Result