-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.html
More file actions
252 lines (232 loc) · 14.8 KB
/
code.html
File metadata and controls
252 lines (232 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!doctype html>
<html lang="en" class="h-100">
<head>
<title>Fizz Buzz: A Coding Project By Chikere Ezekannagha</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/5db21ba9c6.js" crossorigin="anonymous"></script>
<!-- Google Fonts for Teko -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Alfa+Slab+One&family=Teko:wght@300..700&display=swap" rel="stylesheet">
<link href="/css/site.css" rel="stylesheet">
<link href="/css/prism.css" rel="stylesheet">
<link rel="icon" type="image/png" href="/img/favicon.ico">
</head>
<body class="d-flex flex-column h-100">
<!-- === Nav Section === -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top">
<div class="container">
<a class="navbar-brand logoFont" href="#"><img src="/img/favicon-32x32.png" class="d-inline-block align-text-top"
width="32" height="30"> FIZZ BUZZ</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav ms-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="app.html">The App</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="code.html">The Code</a>
</li>
<li class="nav-item">
<a class="nav-link" target="_blank" href="https://github.com/c-eze/FizzBuzz">Git Repo</a>
</li>
<li class="nav-item">
<a class="nav-link" target="_blank" href="https://chikere.dev">About</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- === Main Section === -->
<main class="flex-shrink-0">
<div class="container py-4 px-5 mt-5">
<h1 class="border-1 border-bottom border-dark">The Code for FIZZ BUZZ</h1>
<div class="row">
<div class="col">
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Function - getValues
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
<div class="accordion-body">
<div class="row row-cols-1 row-cols-lg-2">
<div class="col-lg-4 order-lg-last">
<h5>getValues()</h5>
<p>getValues is a controller function that gets the user's fizz and buzz values from the page so
that they can be displayed as multiples for the numbers 1 to 100. It parses the fizz and buzz
values as integers and then passes them along with an array of numbers 1 to 100 to a display
function where they are all printed to the screen.
</p>
</div>
<div class="col-lg-8">
<pre class="line-numbers"><code class="language-javascript">
//get the values from the Page
//starts or controller function
function getValues() {
//get values from the page
let fizzValue = document.getElementById("fizzValue").value;
let buzzValue = document.getElementById("buzzValue").value;
//Need to validate input
//parse into integers
fizzValue = parseInt(fizzValue);
buzzValue = parseInt(buzzValue);
if (Number.isInteger(fizzValue) && Number.isInteger(buzzValue)) {
//call generateNumbers
let numbers = generateNumbers();
//call displayNumbers
displayNumbers(fizzValue, buzzValue, numbers);
} else {
alert("You must enter integers");
}
}
</code>
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Function - generateNumbers
</button>
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
<div class="accordion-body">
<div class="row row-cols-1 row-cols-lg-2">
<div class="col-lg-4 order-lg-last">
<h5>generateNumbers()</h5>
<p>generateNumbers is a logic function that generates and transfers numbers 1 to 100 into an array using
a for loop, and then returns the number array to the calling function.
</p>
</div>
<div class="col-lg-8">
<pre class="line-numbers"><code class="language-javascript">
//logic function
function generateNumbers() {
let numbers = [];
//get all numbers from start to end
for (let index = 1; index <= 100; index++) {
//execute in a loop until index = eValue
numbers.push(index);
}
return numbers;
}
</code>
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Function - displayNumbers
</button>
</h2>
<div id="collapseThree" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
<div class="accordion-body">
<div class="row row-cols-1 row-cols-lg-2">
<div class="col-lg-4 order-lg-last">
<h5>displayNumbers(fValue, bValue, numbers)</h5>
<p>displayNumbers is a display function that displays fizz and buzz values for the numbers 1 to 100 on
to the page. Both the fizz and buzz values are passed into the function along with the number array.
These values are processed using a for loop and if-then-else conditional statements. They are
templated on to the page using different colors to maximize user readability.
</p>
</div>
<div class="col-lg-8">
<pre class="line-numbers"><code class="language-javascript">
//display or view functions
function displayNumbers(fValue, bValue, numbers) {
let templateRows = "";
for (let index = 0; index < numbers.length; index++) {
let className = "";
let number = numbers[index];
if (index % 5 == 0) {
templateRows += `<tr>`;
}
if (number % fValue == 0 && number % bValue == 0) {
className = "fizzBuzz";
templateRows += `<td class="${className}">${className}</td>`;
}
else if (number % fValue == 0) {
className = "fizz";
templateRows += `<td class="${className}">${className}</td>`;
}
else if (number % bValue == 0){
className = "buzz";
templateRows += `<td class="${className}">${className}</td>`;
}
else {
templateRows += `<td class="${className}">${number}</td>`;
}
if ((index + 1) % 5 == 0) {
templateRows += `</tr>`;
}
}
document.getElementById("results").innerHTML = templateRows;
}
</code>
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- === Footer Section === -->
<footer class="footer mt-auto py-3">
<div class="container">
<div class="row row-cols-1 row-cols-lg-3 gy-3">
<div class="col order-last order-lg-first text-light text-center text-lg-start">
<div><span class="text-muted">©2024</span> Chikere</div>
</div>
<div class="col d-flex justify-content-center">
<img src="/img/favicon-32x32.png" alt="Chikere Logo" height="45">
</div>
<div class="col d-flex justify-content-center justify-content-lg-end">
<div class="row">
<div class="col social"><a href="https://www.linkedin.com/in/chikere-ezekannagha/" target="_blank"><i class="fab fa-linkedin fa-2x"></i></a></div>
<div class="col social"><a href="https://github.com/c-eze/" target="_blank"><i class="fab fa-github fa-2x"></i></a></div>
<div class="col social"><a href="https://twitter.com/@chikeredev" target="_blank"><svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path fill="#e7e7e7" d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"/></svg></a></div>
<div class="col social"><a href="https://youtube.com/@chikeredev" target="_blank"><i class="fab fa-youtube fa-2x"></i></a></div>
</div>
</div>
</div>
</div>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous">
</script>
<script src="/js/prism.js"></script>
<script>
Prism.plugins.NormalizeWhitespace.setDefaults({
'remove-trailing': true,
'remove-indent': true,
'left-trim': true,
'right-trim': true
})
</script>
</body>
</html>