-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz.js
More file actions
39 lines (33 loc) · 1.01 KB
/
fizzbuzz.js
File metadata and controls
39 lines (33 loc) · 1.01 KB
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
33
34
35
36
37
38
39
/**
* FizzBuzz Implementation
*
* This program prints numbers from 1 to 10, with the following rules:
* - For multiples of 3, print "Fizz" instead of the number
* - For multiples of 5, print "Buzz" instead of the number
* - For multiples of both 3 and 5, print "FizzBuzz" instead of the number
*/
function fizzbuzz() {
// Loop from 1 to 10
for (let i = 1; i <= 10; i++) {
// Variable to hold the output
let output = '';
// Check if the number is divisible by 3
if (i % 3 === 0) {
output += 'Fizz';
}
// Check if the number is divisible by 5
if (i % 5 === 0) {
output += 'Buzz';
}
// If output is still empty, use the number
if (output === '') {
output = i;
}
// Print the result to the console
console.log(output);
}
}
// Execute the fizzbuzz function
console.log("Starting FizzBuzz:");
fizzbuzz();
console.log("FizzBuzz completed!");