-
Notifications
You must be signed in to change notification settings - Fork 0
/
fizzbuzz.js
39 lines (34 loc) · 868 Bytes
/
fizzbuzz.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
33
34
35
36
37
38
39
// Write a program that prints the numbers from 1 to 100.
for (var i = 0; i < 100; i++) {
console.log(i);
}
// But for multiples of three print “Fizz” instead of the number
for (var i = 0; i < 100; i++) {
if (i % 3 === 0) {
console.log("Fizz");
}
}
// and for the multiples of five print “Buzz”.
for (var i = 0; i < 100; i++) {
if (i % 3 === 0) {
console.log("Fizz");
}
if (i % 5 === 0) {
console.log("Buzz");
}
}
// For numbers which are multiples of both three and five print “FizzBuzz”."
for (var i = 0; i < 100; i++) {
var text = "";
if (i % 3 === 0) {
text = "Fizz";
}
if (i % 5 === 0) {
text += "Buzz";
}
console.log(text || i);
}
// Short version
for (var i = 0; i < 100; i++) {
console.log(i, (!(i%3) ? "Fizz" : "") + (!(i%5) ? "Buzz" : ""))
}