Quick actions

cmd+k|ctrl+k

Navigation

Languages

Nested Loop (Segi tiga)

Snippet info

Language

JavaScript

Visibility

public

Author

riki.whyudi

Created

2022-09-20T03:49:15.335743Z

Updated

2022-09-29T03:07:54.632113Z

let x = '';
for(let i=0; i<5; i++){
    for(let j=0; j<=i; j++){
        x+='*'
    }
    x+='\n'
}

let z = '';
for(let a=5; a>0; a--){
    for(let b=0; b<a; b++){
        z+='*'
    }
    z+='\n'
}
let n = 5;
let y = '';
for(let i=1; i<=n; i++){
   for(let j=1; j<=n-i; j++) {
y+=' ';
}
      for(let k=1; k<=i + (i-1); k++){
y+='*';
  }
y+='\n';
}
console.log(y)
console.log(x)
console.log(z)
INFO