Created
March 13, 2017 00:05
-
-
Save Mattteo1220/ca64a36baa57b714494a315169ffe7b8 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/rovumow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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