JSFiddle - React, Tailwind, and code Playground

by Ashish Kasama

JavaScript

// JavaScript implementation to print the
    // pattern of alphabets A to Z using *
 
    // Below height and width variable can be used
    // to create a user-defined sized alphabet's pattern
 
    // Number of lines for the alphabet's pattern
    let height = 5;
    // Number of character width in each line
    let width = (2 * height) - 1;
 
    // Function to find the absolute value
    // of a number D
    const abs = (d) => {
        return d < 0 ? -1 * d : d;
    }
 
    // Function to print the pattern of 'A'
    const printA = () => {
        let n = parseInt(width / 2), i, j;
        for (i = 0; i < height; i++) {
            for (j = 0; j <= width; j++) {
                if (j == n || j == (width - n)
                    || (i == parseInt(height / 2) && j > n
                        && j < (width - n)))
                    document.write("*");
                else
                    document.write("  ");
            }
            document.write(`<br/>`);
            n--;
        }
    }
 
    // Function to print the pattern of 'B'
    const printB = () => {
        let i, j, half = parseInt(height / 2);
        for (i = 0; i < height; i++) {
            document.write("*");
            for (j = 0; j < width; j++) {
                if ((i == 0 || i == height - 1 || i == half)
                    && j < (width - 2))
                    document.write("*");
                else if (j == (width - 2)
                    && !(i == 0 || i == height - 1
                        || i == half))
                    document.write("*");
                else
                    document.write("  ");
            }
            document.write(`<br/>`);
        }
    }
 
    // Function to print the pattern of 'C'
    const printC = () => {
        let i, j;
        for (i = 0; i < height; i++) {
            document.write("*");
            for (j = 0; j < (height - 1); j++) {
                if (i == 0 || i == height - 1)
                    document.write("*");
  ...