-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.html
330 lines (300 loc) · 13 KB
/
code.html
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!DOCTYPE html>
<html lang="en" class="h-100">
<head>
<title>OneHundred: A Coding Project by Adam Nihiser</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/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<script
src="https://kit.fontawesome.com/5db21ba9c6.js"
crossorigin="anonymous"
></script>
<link href="/css/site.css" rel="stylesheet" />
<link rel="icon" type="image/png" href="/img/hundredicon.png" />
<link href="css/prism.css" rel="stylesheet" />
</head>
<body class="d-flex flex-column h-100">
<!-- ==== Nav Section ==== -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top">
<div class="container-fluid">
<a class="navbar-brand logoFont" href="#"
><img
src="/img/hundredicon.png"
class="d-inline-block"
alt="OneHundred Logo"
width="50"
height="50"
/>
OneHundred</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 me-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/apnihiser/OneHundred"
>Git Repo</a
>
</li>
<!-- <li class="nav-item">
<a
class="nav-link"
target="_blank"
href="https://anihiser-portfolio.netlify.app/"
>About</a
>
</li> -->
</ul>
</div>
</div>
</nav>
<!-- ==== Main Section ==== -->
<main class="flex-shrink-0">
<div class="container py-5 px-5 mt-5">
<h2 class="border-1 border-bottom border-dark">
The Code for OneHundred.
</h2>
<div class="row row-cols-1 row-cols-lg-2">
<div class="col-lg-8">
<pre class="line-numbers"><code class="language-javascript">
//get the values from the interface
//starts or controller function
function getValues(){
//get values from the page
let startValue = document.getElementById("startValue").value;
let endValue = document.getElementById("endValue").value;
//We need to validate our input
//attempt to parse into integers
startValue = parseInt(startValue);
endValue = parseInt(endValue);
if (Number.isInteger(startValue) && Number.isInteger(endValue)) {
//call generateNumbers
let numbers = generateNumbers(startValue, endValue);
//call display numbers
displayNumbers(numbers);
} else {
alert("You must enter integers");
}
}
//generate numbers from the start value to the endValue
//Logic function(s)
function generateNumbers(sValue, eValue){
let numbers = [];
//get all numbers from start to end
for(let i = sValue; i <= eValue; i++){
//this will execute in a loop until index + eValue
numbers.push(i);
}
return numbers;
}
//display the numbers and mark even numbers bold
//display or view functions
function displayNumbers(numbers){
let templateRows = "";
for (let i = 0; i < numbers.length; i++) {
let className = "even";
let number = numbers[i];
if(number % 2 == 0){
className = "even";
} else {
className = "odd";
}
templateRows += `<tr><td class="${className}">${number}</td></tr>`;
}
document.getElementById("results").innerHTML = templateRows;
}
</code>
</pre>
</div>
<div class="col-lg-4">
<h5>One Hundred - The APP Breakdown</h5>
<p>
"One Hundred" is a Javascript application written to gather a
beginning value and ending value, validate the information, then
render a table containing the range of numbers with all evens
displayed in <strong>bold</strong>.
</p>
<p>The application is broken down into 3 functions.</p>
<ul>
<li>The Controller function</li>
<li>The Logic function</li>
<li>The View function</li>
</ul>
<br />
<h5>Controller Fuction</h5>
<p>
The Controller Function
<span class="highlight">getValues()</span> works on several
important discreet operations which receives inputs, validates
data, and controls when other functions in the application are
executed.
</p>
<p>Lets break these operations down individually</p>
<h6>Input</h6>
<p>
By using a form, we have structured the web application in such a
way that either by default or with user defined values, we can
capture the necessary information to begin the process of running
the application. Once the input values have been entered into the
web form, the user can submit the data by click on the button.
</p>
<h6>Validation</h6>
<p>
Validation is required here since the application will fail if a
string or text char is provided by the user. Also the values
provided will be a string data type. Therefore the
<span class="highlight">parseInt()</span> and
<span class="highlight">isInteger()</span> Javascript functions
are used to ensure that all data sent to be processed are valid.
If any of this fails validation, the webpage will alert the user
with "You must enter integers"
</p>
<h6>Function Calls</h6>
<p>
Lastly, this controller function will pass these validated values
into the appropriate functions next. Both
<span class="highlight">generateNumbers()</span> and
<span class="highlight">displayNumbers()</span> are self
explanatory in their purpose, but see the Logic function and View
function below for more details.
</p>
<br />
<h5>Logic Function</h5>
<p>
The <span class="highlight">generateNumbers()</span> function does
just that. It will accept the validated numbers from
<span class="highlight">getValues()</span> and pass them through a
for loop which will increment and
<span class="highlight">push()</span> them into the numbers array
until the index in the for loop is equal to the endValue. Once the
for loop has been completed the
<span class="highlight">generateNumbers()</span> function will
return the array back to the
<span class="highlight">getValues()</span> function
</p>
<br />
<h5>View Function</h5>
<p>
The numbers array from the
<span class="highlight">generatenumbers()</span> function will
need to be rendered on the webpage. Step one will be to loop
through the arrays using a for loop. We will be inserting these
values into Template Literals by means of a string variable. The
HTML that these template literals are saved to will be in the
table row, table data format which will be rended into a table
with one column. The even numbers will pass a boolean check using
modulo to check if the remainder of being divided by two equals 0.
Lastly this will be inserted into the HTML page by use of
innerHTML Javascript function.
</p>
</div>
</div>
</div>
</main>
<!-- ==== Footer Section ==== -->
<footer class="footer mt-auto py-3 sticky-footer">
<div class="container-fluid">
<div class="row row-cols-1 row-cols-lg-3">
<div
class="col order-last order-lg-first text-light d-flex align-items-end justify-content-start gy-2"
>
<div>
<span class="text-muted">©2021</span> Adam Nihiser |
</div>
</div>
<div
class="col d-flex align-items-end justify-content-start justify-content-lg-center gy-3"
>
<img
src="/img/ANihiser_NewWordmark.png"
alt="Adam Nihiser Logo"
height="32"
/>
</div>
<div
class="col d-flex align-items-end justify-content-start justify-content-lg-end gy-3"
>
<div class="row">
<div class="col social">
<a href="https://www.linkedin.com/in/anihiser/" target="_blank"
><i class="fab fa-linkedin fa-2x"></i
></a>
</div>
<div class="col social">
<a href="https://github.com/apnihiser" target="_blank"
><i class="fab fa-github fa-2x"></i
></a>
</div>
<div class="col social">
<a href="https://twitter.com/That_APN_Guy" target="_blank"
><i class="fab fa-twitter fa-2x"></i
></a>
</div>
<div class="col social">
<a
href="https://www.youtube.com/channel/UCZl9auJaZm4S3sOHCBcxgEQ"
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/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF"
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>