-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (30 loc) · 845 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// --- Directions
// Write a program that console logs the numbers
// from 1 to n. 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”.
// --- Example
// fizzBuzz(5);
// 1
// 2
// fizz
// 4
// buzz
function fizzBuzz(n) {
for (let i = 1; i <= n; i++) {
// Is the number multiple of 3 and 5?
if(i % 3 === 0 && i % 5 === 0) {
console.log('fizzbuzz');
// Is the number multiple of 3?
} else if (i % 3 === 0) {
console.log('fizz');
// Is the number multiple of 5?
} else if (i % 5 === 0) {
console.log('buzz');
} else {
console.log(i);
}
}
}
module.exports = fizzBuzz;