forked from pratyushmp/code_opensource_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx_star.js
More file actions
25 lines (24 loc) · 637 Bytes
/
Copy pathx_star.js
File metadata and controls
25 lines (24 loc) · 637 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
input = parseInt(prompt('Banyak bintang ?'))
// inisiasi
let bintang;
if (input < 1 || input > 20) {
console.log('Input must 1 - 20')
} else {
bintang = input * 2 + 2
}
// sebanyak bintang yang di inginkan
for (i = 1; i < bintang; i++) {
for (j = 1; j < bintang; j++) {
// buat bintang yang menyerong kiri
if (i == j) {
document.write('*')
} else if ((i + j) == bintang) {
// bintang yang menyerong kanan
document.write('*')
} else {
// sisanya whitespace
document.write(' ')
}
}
document.write('<br>')
}