{"id":1,"date":"2014-12-21T22:41:18","date_gmt":"2014-12-21T22:41:18","guid":{"rendered":"https:\/\/code.jamesash.com\/?p=1"},"modified":"2019-02-19T18:19:09","modified_gmt":"2019-02-19T18:19:09","slug":"hello-world","status":"publish","type":"post","link":"https:\/\/code.jamesash.com\/?p=1","title":{"rendered":"FizzBuzz!"},"content":{"rendered":"<p>I came across a FizzBuzz problem while trying to come up with some sample code. \u00a0The problem is pretty simple.<\/p>\n<blockquote><p><span style=\"line-height: 1.6471;\">Write a program that prints the numbers from 1 to 100. But for multiples of 3 print \u201cFizz\u201d instead of the number and for the multiples of five print \u201cBuzz\u201d. For numbers which are multiple of both 3 and 5, print \u201cFizzBuzz\u201d.<\/span><\/p><\/blockquote>\n<p><span style=\"line-height: 1.6471;\">Multiple sources said that only 1% of programmers could solve this problem. \u00a0That makes me think too many people call themselves programmers.<\/span><\/p>\n<p>It took me about 10 minutes to come up with this in javascript:<\/p>\n<pre><code>\nfor (var i=1; i &lt;=100; i++) {\n   var x = '';\n   if (!(i%3)) {\n      x += 'Fizz';\n   }\n   if (!(i%5)) {\n      x += 'Buzz';\n   }\n   if (x.length == 0) {\n      x = i;\t\n   } \n   document.write(x + \"&lt;br&gt;\");\n}\n<\/code><\/pre>\n<p>That worked great. \u00a0<a href=\"http:\/\/codepen.io\/anon\/pen\/LEZvvG\">You can see it at CodePen<\/a>. \u00a0After I finished, I looked at some other answers and found a couple of ways to improve it. \u00a0Initially, I wanted to else if all the way through my options, but I had a brainfart and didn&#8217;t think of checking if it is divisible by 15. \u00a0You can also check to see if x is null and if it is, write i, but I didn&#8217;t want to do it that way. \u00a0Here is the final code (<a href=\"http:\/\/codepen.io\/anon\/pen\/qENwGO\" target=\"_blank\" rel=\"noopener\">CodePen<\/a>):<\/p>\n<pre><code>\nfor (var i=1; i &lt;=100; i++) {\n    var x = '';\n    if (!(i%15)) {\n      x = 'FizzBuzz';\n    } else if (!(i%3)) {\n      x = 'Fizz';\n    } else if (!(i%5)) {\n      x = 'Buzz';\n    } else {\n      x = i;\t\n    } \n document.write(x + \"&lt;br&gt;\");\n}\n<\/code><\/pre>\n<p>I hope you enjoyed that. It was a fun exercise. I&#8217;ll probably write one in ColdFusion soon.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I came across a FizzBuzz problem while trying to come up with some sample code. \u00a0The problem is pretty simple. Write a program that prints the numbers from 1 to 100. But for multiples of 3 print \u201cFizz\u201d instead of the number and for the multiples of five print \u201cBuzz\u201d. For numbers which are multiple &hellip; <a href=\"https:\/\/code.jamesash.com\/?p=1\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">FizzBuzz!<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,3,4],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-code-sample","tag-fizzbuzz","tag-javascript"],"_links":{"self":[{"href":"https:\/\/code.jamesash.com\/index.php?rest_route=\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.jamesash.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.jamesash.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.jamesash.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code.jamesash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1"}],"version-history":[{"count":6,"href":"https:\/\/code.jamesash.com\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":18,"href":"https:\/\/code.jamesash.com\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions\/18"}],"wp:attachment":[{"href":"https:\/\/code.jamesash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.jamesash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.jamesash.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}