Back
I want to print some patterns with stars, can someone help me with this?
You can do it like this:
for (let i = 1; i <= 5; i++) { for (let j = 1; j <= i; j++) { document.write('*'); } document.write('<br />');}
for (let i = 1; i <= 5; i++) {
for (let j = 1; j <= i; j++) {
document.write('*');
}
document.write('<br />');
If you want a pyramid:
function pyramid(n) { for(i=1 ;i<=n;i++) { let str = ' '.repeat(n-i); let str2 = '*'.repeat(i*2-1); console.log(str + str2 + str); }}pyramid(5)
function pyramid(n) {
for(i=1 ;i<=n;i++) {
let str = ' '.repeat(n-i);
let str2 = '*'.repeat(i*2-1);
console.log(str + str2 + str);
pyramid(5)
Want to be web developer? Check out the full stack developer course from Intellipaat.
31k questions
32.8k answers
501 comments
693 users