Created
October 30, 2011 17:42
-
-
Save sanemat/1326175 to your computer and use it in GitHub Desktop.
javascript fizzbuzz
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
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 | |
}; | |
}()); | |
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
How can I use this fizzBuzz variable?
In node repl, in my expect: