Skip to content

Instantly share code, notes, and snippets.

@Mattteo1220
Created March 13, 2017 00:05
Show Gist options
  • Save Mattteo1220/ca64a36baa57b714494a315169ffe7b8 to your computer and use it in GitHub Desktop.
Save Mattteo1220/ca64a36baa57b714494a315169ffe7b8 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/rovumow
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function fizzBuzz(countTo) {
var result = [];
for (var i=1; i <= countTo; i++) {
if (i % 15 === 0) {
result.push('fizzbuzz');
}
else if (i % 5 === 0) {
result.push('buzz');
}
else if (i % 3 === 0) {
result.push('fizz');
}
else {
result.push(i);
}
}
return result;
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
*/
// tests
(function testFizzBuzz() {
// we'll use the variables in our test cases
var countTo = 16;
var expected = [
1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz',
'buzz', 11, 'fizz', 13, 14, 'fizzbuzz', 16
];
var actual = fizzBuzz(countTo) || [];
if (
expected.length === actual.length &&
expected.every(function(item, index) {
return actual[index] === item;}) ) {
console.log('SUCCESS: fizzBuzz is working');
}
else {
console.log('FAILURE: fizzBuzz is not working');
}
})();
</script>
<script id="jsbin-source-javascript" type="text/javascript">function fizzBuzz(countTo) {
var result = [];
for (var i=1; i <= countTo; i++) {
if (i % 15 === 0) {
result.push('fizzbuzz');
}
else if (i % 5 === 0) {
result.push('buzz');
}
else if (i % 3 === 0) {
result.push('fizz');
}
else {
result.push(i);
}
}
return result;
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
*/
// tests
(function testFizzBuzz() {
// we'll use the variables in our test cases
var countTo = 16;
var expected = [
1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz',
'buzz', 11, 'fizz', 13, 14, 'fizzbuzz', 16
];
var actual = fizzBuzz(countTo) || [];
if (
expected.length === actual.length &&
expected.every(function(item, index) {
return actual[index] === item;}) ) {
console.log('SUCCESS: fizzBuzz is working');
}
else {
console.log('FAILURE: fizzBuzz is not working');
}
})();</script></body>
</html>
function fizzBuzz(countTo) {
var result = [];
for (var i=1; i <= countTo; i++) {
if (i % 15 === 0) {
result.push('fizzbuzz');
}
else if (i % 5 === 0) {
result.push('buzz');
}
else if (i % 3 === 0) {
result.push('fizz');
}
else {
result.push(i);
}
}
return result;
}
/* From here down, you are not expected to
understand.... for now :)
Nothing to see here!
*/
// tests
(function testFizzBuzz() {
// we'll use the variables in our test cases
var countTo = 16;
var expected = [
1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz',
'buzz', 11, 'fizz', 13, 14, 'fizzbuzz', 16
];
var actual = fizzBuzz(countTo) || [];
if (
expected.length === actual.length &&
expected.every(function(item, index) {
return actual[index] === item;}) ) {
console.log('SUCCESS: fizzBuzz is working');
}
else {
console.log('FAILURE: fizzBuzz is not working');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment