-
-
Save ryanguill/3143875 to your computer and use it in GitHub Desktop.
Fizz Buzz
This file contains hidden or 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
<!--- cf function that solves the fizzbuzz test ---> | |
<!--- I generally don't like functions outputing themselves, | |
I would rather have it do a return - gives you more flexability later ---> | |
<cffunction name="displayFBMsg" access="private" hint="whatever..."><!--- no returntype / no output ---> | |
<cfargument name="numberOfIterations" required="true" type="numeric"><!--- personal preference, I like name, type, required, but thats not a big deal ---> | |
<cfloop from="1" to="#arguments.numberOfIterations#" index="i"><!--- i is not var'd ---> | |
<!--- with this logic, you're going to do at least 2 checks on every number, | |
and if those pass, you'll do 4, regardless (just as a comparison) ---> | |
<cfif i MOD 3 EQ 0 OR i MOD 5 EQ 0> | |
<cfif i MOD 3 EQ 0>fizz</cfif><cfif i MOD 5 EQ 0>buzz</cfif> | |
<cfelse> | |
<cfoutput>#i#</cfoutput> | |
</cfif> | |
</br> | |
</cfloop> | |
</cffunction> | |
<!--- call the function ---> | |
<cfoutput>#displayFBMsg(100)#</cfoutput><!--- I like that you parametized the number of iterations ---> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment