Day 64: Pattern using loops of 100DaysCodingChallenge
Hello all,
#day64
Day64
Today's my task was to Print the below Pattern using loops.
Full Triangle by Alphabets
A
B C D
E F G H I
J K L M N O P
Q R S T U V W X Y
I have started the 100 days of coding challenge to improve my programming skills..
Code :
let n = prompt("Enter a number : "); //let n = 5; let string = ""; let count = 0; // External loop for (let i = 1; i <= n; i++) { // creating spaces for (let j = 0; j < n - i; j++) { string += " "; } // creating alphabets for (let k = 0; k < 2 * i - 1; k++) { string += String.fromCharCode(count + 65) +" "; count++; } string += "\n"; } console.log(string);
Output :
Happy Coding:)
Thank you...
Comments
Post a Comment