Skip to content

Commit 8254f41

Browse files
author
Coding Money
committed
fizzbuzz
1 parent 1ae8a5a commit 8254f41

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Diff for: 10-fizzbuzz.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
17+
fizzBuzz(5)

Diff for: completed_exercises/10-fizzbuzz.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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(let i=1; i<=n; i++){
17+
if(i % 3 === 0 && i % 5 === 0){
18+
console.log('fizzbuzz')
19+
}else if( i % 3 === 0 ){
20+
console.log('fizz')
21+
}else if( i % 5 === 0){
22+
console.log('buzz')
23+
}else{
24+
console.log(i)
25+
}
26+
}
27+
}
28+
29+
fizzBuzz(20)

0 commit comments

Comments
 (0)