File tree 2 files changed +46
-0
lines changed
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments