A mirror of my website's source code.

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 fizzbuzz.html

View raw Download
text/html • 5.7 kiB
HTML document, ASCII text, with very long lines (2589)
        
            
1
<!DOCTYPE html>
2
<html lang="en-us" prefix="og: https://ogp.me/ns#">
3
4
<head>
5
6
7
<meta charset="UTF-8" />
8
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
<title>The FizzBuzz Program - S0G</title>
10
<link rel="stylesheet" href="/src/global.css" />
11
<meta property="og:locale" content="en_US"/>
12
<meta property="og:site_name" content="Steve0Greatness' Site"/>
13
14
<link rel="stylesheet" href="/src/pygments-friendly.css" />
15
<link rel="stylesheet" href="/src/blog.css" />
16
<link rel="alternate" href="/blog/fizzbuzz.txt" type="text/plain" title="Post source" />
17
<meta property="og:title" content="The FizzBuzz Program" />
18
<meta property="og:url" content="https://steve0greatness.github.io/blog/fizzbuzz.html" />
19
20
</head>
21
22
<body>
23
<header>
24
<h2><a href="/">Steve0Greatness</a></h2>
25
<nav>
26
<a href="/blog">Blog</a>
27
<a href="/link-tree.html">Link Tree</a>
28
</nav>
29
</header>
30
31
<ol role="navigation" class="breadcrumbs" aria-roledescription="Site breadcrumb">
32
<li>
33
<a href="/">Index</a>
34
</li>
35
36
<li >
37
<a href="/blog">
38
Blog Index
39
</a>
40
</li>
41
42
<li aria-current="location">
43
44
The FizzBuzz Program
45
46
</li>
47
48
</ol>
49
<main>
50
<article>
51
<header>
52
<h2 id="blog-post-titled">The FizzBuzz Program</h2>
53
<div role="toolbar" class="toolbar">
54
<a href="https://toot.kytta.dev/?text=Take a look at this article by @S0G@mastodon.social: https://steve0greatness.github.io/blog/fizzbuzz.html" title="Share to Mastodon">
55
<img src="/toot-kytta-dev-icon.svg" width="16" height="16" aria-hidden="true" title="Share to Mastodon" />
56
</a>
57
<a href="/blog/fizzbuzz.html" title="Direct link">
58
<span aria-hidden="true">
59
&#128279;
60
</span>
61
</a>
62
<a href="/blog/fizzbuzz.txt" title="Markdown source">
63
<img src="/md-src.svg" width="16" height="16" aria-hidden="true" />
64
</a>
65
</div>
66
<time>2022 Feb 20</time>
67
</header>
68
<p><p>A FizzBuzz Program is a program used in many job interviews to see if a programmer is good at problem solving. There are many ways to make one.</p><p>First let me tell you why I write these programs. These programs, at least in my opinion, are good when you're learning a new programming language. It gives you a problem to solve, and all you need to do to solve it. Incase you're wondering, the problem is to make a program that counts from 1 to 100 and replaces all multiples of 3 with Fizz, all multiples of 5 with Buzz, and multiples of both with FizzBuzz. Generally in interviews, they also ask you to add on more multiples, such as multiples of 7 are replaced with Fuzz, and multiples of 11 are replaced with Bizz.</p><p>Now that I've told you what a FizzBuzz Program is, let me show you how I make them in Psuedo-Code.</p><div class="code">for i in 1-100 {<div style="margin-left:1em">toPrint = ""<br>print(toPrint)</div>}</div><p>The first thing I do is I create a for loop, and within it I put a print statement and a variable named toPrint.</p><div class="code">def check(checktomulti, multi, toreturn) {<div style="margin-left:1em">if checktomulti % multi == 0 {<div style="margin-left:1em">return toreturn</div>}<br>return ""</div>}<br>def checkEmpty(string, number) {<div style="margin-left:1em">if string == "" {<div style="margin-left:1em">return number</div>}<br>return string</div>}<br>for i in 1-100 {<div style="margin-left:1em">toPrint = checkEmpty(check(i, 3, "Fizz") + check(i, 5, "Buzz"), i)<br>print(toPrint)</div>}</div><p>The next thing I do is I define a function that checks if one number is a multiple of another, and if it is, then it returns the string, otherwise, it returns an empty string.</p><p>Then I make a function that checks if a string is an empty one, if it is, then it returns a number.</p><p>Once I have these 2 functions, I go back into the for loop and make the toPrint variable have the variable for checking if a string is empty(and if it is replace it with a number) check if 2 of the other function that check if one number is a multiple of another(and if it is, return a string). Finally, it prints the output.</p><p>I've tried this method many times. Below are some examples of this method in action!</p><ul><li><a href="https://replit.com/@StevesGreatness/FizzBuzzKotlin">Kotlin</a></li><li><a href="https://replit.com/@StevesGreatness/FizzBuzzlua">Lua</a></li><li><a href="https://replit.com/@StevesGreatness/FizzBuzzpython">Python</a></li><li><a href="https://replit.com/@StevesGreatness/FizzBuzzRuby">Ruby</a></li></ul></p>
69
70
</article>
71
</main>
72
<footer role="group">
73
<div class="footer-link-list-holder">
74
<span aria-hidden="true" id="footer-label-site-details" class="footer-link-list-label">Site Meta</span>
75
<ol class="footer-link-list" aria-labelledby="footer-label-site-details">
76
<li><a href="https://github.com/Steve0Greatness/steve0greatness.github.io">Github Repository</a></li>
77
<li><a href="https://steve0greatness.github.io/extras">Extras Archive</a></li>
78
</ol>
79
</div>
80
<div class="footer-link-list-holder">
81
<span aria-hidden="true" id="footer-label-social-accounts" class="footer-link-list-label">Social Accounts</span>
82
<ol class="footer-link-list" aria-labelledby="footer-label-social-accounts">
83
<li><a href="https://mastodon.social/@S0G" rel="me">Mastodon</a></li>
84
<li><a href="https://youtube.com/@s0g">YouTube</a></li>
85
<li><a href="/link-tree.html">More...</a></li>
86
</ol>
87
</div>
88
</footer>
89
</body>
90
91
</html>