Skip to content

Instantly share code, notes, and snippets.

@sanemat
Created October 30, 2011 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanemat/1326175 to your computer and use it in GitHub Desktop.
Save sanemat/1326175 to your computer and use it in GitHub Desktop.
javascript fizzbuzz
describe('FizzBuzz', function(){
it('should say number', function(){
expect(fizzBuzz.say(1)).toEqual(1);
});
it('should say fizz on 3', function(){
expect(fizzBuzz.say(3)).toEqual('fizz');
});
it('should say buzz on 5', function(){
expect(fizzBuzz.say(5)).toEqual('buzz');
});
it('should say fizzbuzz on 15', function(){
expect(fizzBuzz.say(15)).toEqual('fizzbuzz');
});
});
var fizzBuzz = (function () {
var say = function (number){
if (number % 3 == 0 && number % 5 == 0) {
return 'fizzbuzz';
} else if (number % 3 == 0) {
return 'fizz';
} else if (number % 5 == 0) {
return 'buzz';
}
return number;
};
return {
say: say
};
}());
@sanemat
Copy link
Author

sanemat commented Oct 30, 2011

How can I use this fizzBuzz variable?

In node repl, in my expect:

var fizzBuzz = require('./FizzBuzzSpec.js')
But it does not work:
ReferenceError: describe is not defined
Then I commented out describe block, but it does also not work.

@sanemat
Copy link
Author

sanemat commented Oct 30, 2011

copy and paste from var fizzBuzz [line:15] to }()); [line:29],
then

for (var i = 1; i<=100; i++) { console.log(fizzBuzz.say(i)) }
I soloved my executing problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment