Skip to content

Commit 8e3fac2

Browse files
committed
[added]: First Challenge
1 parent 846fe83 commit 8e3fac2

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

.github/pull_request_template.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## New Pull Request
2+
3+
<!-- Before Submitting the pull request make sure the following checklist is complete. -->
4+
5+
- [ ] Added the problem statement to the README.md
6+
- [ ] Added the solution to the problem in /solutions/problem_title/answer.js
7+
- [ ] Descriptive Comments
8+
- [ ] Explained the solution in /solutions/problem_title/readme.md
9+
- [ ] Format for pull request [type]: Description
10+
- [ ] Bug free code
11+
12+
<!-- For referencing the Issue solved use Fixed: #issueNumber -->

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# JS Coding Challenges
2+
3+
This repository contains a collection of JavaScript coding challenges that are designed to help you improve your skills and test your knowledge of the language. Each challenge is accompanied by a README file that explains the problem statement, input/output, and any additional requirements.
4+
5+
The answers will be available in /solutions/problem_title/answer.js while the explanation will be given in /solutions/problem_title/readme.md.
6+
7+
Make sure to star the repository if you find it useful. And contributions to the repository are welcome.
8+
9+
## Challenge 1: FizzBuzz
10+
11+
Write a program that prints the numbers from 1 to 100. But for multiples of three, print "Fizz" instead of the number and for the multiples of five, print "Buzz". For numbers which are multiples of both three and five, print "FizzBuzz". For example, your program should print:
12+
13+
```javascript
14+
1
15+
2
16+
Fizz
17+
4
18+
Buzz
19+
Fizz
20+
7
21+
8
22+
Fizz
23+
Buzz
24+
11
25+
Fizz
26+
13
27+
14
28+
FizzBuzz
29+
16
30+
...
31+
```

solutions/ch_1_FizzBuzz/answer.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Iterate from 1 to 100
2+
for (let i = 1; i <= 100; i++) {
3+
// If the number is divisible by both 3 and 5, print 'FizzBuzz'
4+
if (i % 3 === 0 && i % 5 === 0) {
5+
console.log("FizzBuzz");
6+
}
7+
// If the number is divisible by 3, print 'Fizz'
8+
else if (i % 3 === 0) {
9+
console.log("Fizz");
10+
}
11+
// If the number is divisible by 5, print 'Buzz'
12+
else if (i % 5 === 0) {
13+
console.log("Buzz");
14+
}
15+
// Otherwise, print the number itself
16+
else {
17+
console.log(i);
18+
}
19+
}

solutions/ch_1_FizzBuzz/readme.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Challenge 1: FizzBuzz
2+
3+
Write a program that prints the numbers from 1 to 100. But for multiples of three, print "Fizz" instead of the number and for the multiples of five, print "Buzz". For numbers which are multiples of both three and five, print "FizzBuzz". For example, your program should print:
4+
5+
```javascript
6+
1
7+
2
8+
Fizz
9+
4
10+
Buzz
11+
Fizz
12+
7
13+
8
14+
Fizz
15+
Buzz
16+
11
17+
Fizz
18+
13
19+
14
20+
FizzBuzz
21+
16
22+
...
23+
```
24+
25+
## Answer Explanation
26+
27+
In short, the program loops over the numbers from 1 to 100, and for each number, it checks if it is divisible by 3, 5, or both. If it is divisible by 3, it prints 'Fizz', if it is divisible by 5, it prints 'Buzz', and if it is divisible by both 3 and 5, it prints 'FizzBuzz'. If it is not divisible by either 3 or 5, it simply prints the number itself.

0 commit comments

Comments
 (0)