POLA BINTANG DENGAN FOR
--> bintang kebawah nambah, di sebelah kiri var s = ' '; for( var i = 0; i < 10; i++ ) { for( var j = 0; j <= i; j++ ) { s += '*'; } s += '\n'; } console.log(s); ----------------------------------------------------------------- --> bintang kebawah kurang, di sebelah kiri var s = ' '; for( var i = 10; i > 0; i-- ) { for( var j = 0; j < i; j++) { s += '*'; } s += '\n'; } console.log(s); ----------------------------------------------------------------- --> bintang kebawah nambah, di sebelah kanan var s = ' '; for( var i = 10; i > 0; i-- ) { for(var j = 0; j <= i; j++ ) { s += ' '; } for( var k = 10; k >= i; k-- ) { s += '*'; } s += '\n'; } console.log(s); ----------------------------------------------------------------- --> bintang kebawah kurang, di sebelah kanan var s = ' '; for( var i = 10; i >= 1; i-- ) { for( var j = i; j <= 10; j++ ) { s += ' '; } for( var k = 1; k <= i; k++ ) { s += '*'; } s += '\n'; } console.log(s); -----------------------------------------------------------------
--> bintang kebawah nambah-kurang, di sebelah kiri var s = ' '; for ( var i = 0; i < 10; i ++ ) { for ( var j = 0; j <= i; j++ ) { s += '*'; } s += '\n'; } for ( var i = 10; i > 0; i-- ) { for ( var k = 0; k < i; k++ ){ s += '*'; } s += '\n'; } console.log(s);
-----------------------------------------------------------------
--> bintang kebawah nambah, di tengah / pyramid var s = ' '; for ( var i = 10; i > 0; i-- ) { for ( var j = 1; j <= i; j++ ) { s += ' '; } for ( var k = 10; k >= i; k-- ) { s += '*'; } for ( var l = 10; l > i; l-- ) { s += '*'; } s += '\n'; } console.log(s);
-----------------------------------------------------------------
--> bintang kebawah kurang, di tengah / pyramid kebalik
var s = ' ';
for ( i = 0; i <= 10; i++ ) {
for ( j = 1; j <= i; j++ ) {
s += ' ';
}
for ( k = 10; k >= i; k-- ) {
s += '*';
}
for ( l = 10; l > i; l-- ) {
s += '*';
}
s += '\n';
}
console.log(s);
-----------------------------------------------------------------
--> bintang kebawah nambah-kurang, di tengah
var s = ' ';
for ( var a = 10; a > 0; a-- ) {
for ( var b = 1; b <= a; b++ ) {
s += ' ';
}
for ( var c = 10; c >= a; c-- ) {
s += '*';
}
for ( var d = 10; d > a; d-- ) {
s += '*';
}
s += '\n';
}
for ( i = 0; i <= 10; i++ ) {
for ( j = 1; j <= i; j++ ) {
s += ' ';
}
for ( k = 10; k >= i; k-- ) {
s += '*';
}
for ( l = 10; l > i; l-- ) {
s += '*';
}
s += '\n';
}
console.log(s);
-----------------------------------------------------------------
JANGAN LUPA ;
0 Komentar