Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f18a19e

Browse files
Adding fizzbuzz
1 parent 914e94a commit f18a19e

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

‎fizzBuzz/directions.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# --- Directions
2+
Write a program that console logs the numbers
3+
from 1 to n. But for multiples of three print
4+
"fizz" instead of the number and for the multiples
5+
of five print "buzz". For numbers which are multiples
6+
of both three and five print "fizzbuzz".
7+
8+
# --- Example
9+
10+
fizzBuzz(5);
11+
1
12+
2
13+
fizz
14+
4
15+
buzz
16+
17+
18+
# --- Solutions
19+
20+
Solution No.1
21+
22+
function fizzBuzz(n) {
23+
for(i = 1; i <=n; i++){
24+
if(n%3 === 0 && n%5 === 0) {
25+
console.log("fizzbuzz");
26+
} else if (n%3 === 0) {
27+
console.log("fizz");
28+
} else if (n%5 === 0) {
29+
console.log("buzz");
30+
} else {
31+
console.log(i);
32+
}
33+
}
34+
}

‎fizzBuzz/fizzBuzz.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// --- Directions
2+
// Write a program that console logs the numbers
3+
// from 1 to n. But for multiples of three print
4+
// "fizz" instead of the number and for the multiples
5+
// of five print "buzz". For numbers which are multiples
6+
// of both three and five print "fizzbuzz".
7+
// --- Example
8+
// fizzBuzz(5);
9+
// 1
10+
// 2
11+
// fizz
12+
// 4
13+
// buzz
14+
15+
function fizzBuzz(n) {
16+
for(i = 1; i <=n; i++){
17+
if(n%3 === 0 && n%5 === 0) {
18+
console.log("fizzbuzz");
19+
} else if (n%3 === 0) {
20+
console.log("fizz");
21+
} else if (n%5 === 0) {
22+
console.log("buzz");
23+
} else {
24+
console.log(i);
25+
}
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /