Skip to content

Instantly share code, notes, and snippets.

@dydx
Created November 21, 2015 04:52
Show Gist options
  • Save dydx/5ef87a3f0028b3ef77a4 to your computer and use it in GitHub Desktop.
Save dydx/5ef87a3f0028b3ef77a4 to your computer and use it in GitHub Desktop.
var result;
var max = 20;
function fizzbuzz (x) {
if (x % 15 === 0) {
return 'fizzbuzz';
} else if (x % 3 === 0) {
return 'fizz';
} else if (x % 5 === 0) {
return 'buzz';
} else {
return x;
}
}
function fizzbuzzUpTo (x) {
for(var i = 1; i <= x; i++) {
console.log(fizzbuzz(i));
}
}
fizzbuzzUpTo(max);
console.log('--------');
function fizzbuzzBetween(x, y) {
for(var i = x; i <= y; i++) {
console.log(fizzbuzz(i));
}
}
console.log('--------');
fizzbuzzBetween(11, 27);
for(var i = 1; i <= 20; i++) {
result = "";
if (i % 15 === 0) {
result = 'fizzbuzz';
} else if (i % 3 === 0) {
result = 'fizz';
} else if (i % 5 === 0) {
result = 'buzz';
} else {
result = i;
}
console.log(result);
}
console.log('--------');
for(var i = 1; i <= 20; i++) {
result = "";
if (i % 3 === 0) {
result += 'fizz';
} else if (i % 5 === 0) {
result += 'buzz';
} else {
result += i;
}
console.log(result);
}
console.log('--------');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment