Skip to content

Commit a800b40

Browse files
authored
Merge pull request swaaz#386 from swaaz/hacktoberfest
Hacktoberfest
2 parents e52f37b + 7fcdb22 commit a800b40

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

Javascript/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
| [Program-13](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/Javascript/program-13/program.js) | Asyncronous function program
2020
| [Program-14](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/Javascript/program-14/program.js) | Create multiple objects with same body using a constructor function
2121
| [Program-15](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/Javascript/program-15/program.js) | Classes in Javascript
22+
| [Program-16](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/Javascript/program-16/program.js) | Hollow Diamond
2223

2324
</div>
2425

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
let n = 5;
2+
let string = "";
3+
// Upside pyramid
4+
// upside diamond
5+
for (let i = 1; i <= n; i++) {
6+
// printing spaces
7+
for (let j = n; j > i; j--) {
8+
string += " ";
9+
}
10+
// printing star
11+
for (let k = 0; k < i * 2 - 1; k++) {
12+
if (k === 0 || k === 2 * i - 2) {
13+
string += "*";
14+
}
15+
else {
16+
string += " ";
17+
}
18+
}
19+
string += "\n";
20+
}
21+
// downside diamond
22+
for (let i = 1; i <= n - 1; i++) {
23+
// printing spaces
24+
for (let j = 0; j < i; j++) {
25+
string += " ";
26+
}
27+
// printing star
28+
for (let k = (n - i) * 2 - 1; k >= 1; k--) {
29+
if (k === 1 || k === (n - i) * 2 - 1) {
30+
string += "*";
31+
}
32+
else {
33+
string += " ";
34+
}
35+
}
36+
string += "\n";
37+
}
38+
console.log(string);

Javascript/program - 16/read.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Program-16
2+
## Program to print hollow diamond

0 commit comments

Comments
 (0)