// 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("*");
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.