-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzz.js
More file actions
38 lines (32 loc) · 922 Bytes
/
FizzBuzz.js
File metadata and controls
38 lines (32 loc) · 922 Bytes
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
/* Print all the number from 1 to 100, with two exceptions. For numbers divisible by 3, print "Fizz" instead of the number, and for numbers divisible by 5, print "Buzz" instead. */
for (let i = 1; i <= 100; i++) {
if (i % 3 != 0) {
console.log("Fizz");
} else {
console.log(i);
}
}
for (let i = 1; i <= 100; i++) {
if (i % 5 != 0) {
console.log("Buzz");
} else {
console.log(i);
}
}
/* Modify your program to print "FizzBuzz" for numbers that are divisible by both 3 and 5 */
for (let i = 1; i <= 100; i++){
if ((i % 3 != 0) && (i % 5 != 0)) {
console.log("FizzBuzz");
}
else console.log(i);
}
/* and still print "Fizz" or "Buzz" for numbers divisible by only one of those. */
for (let i = 1; i <= 100; i++) {
if (i % 3 != 0) {
console.log("Fizz");
}
else if (i % 5 != 0) {
console.log("Buzz");
}
else console.log(i);
}