-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.html
234 lines (217 loc) · 13.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Code</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
<!-- google fonts -->
<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=Alkatra:wght@400;500;600;700&family=Allan:wght@400;700&family=Bebas+Neue&family=Delicious+Handrawn&family=Fira+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Mallanna&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet">
<!-- bootstrap icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<!-- css -->
<link rel="stylesheet" href="/css/site.css">
<link rel="stylesheet" href="/css/prism.css">
<!-- dev icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css">
<!-- favicon -->
<link rel="shortcut icon" href="/images/favicon_io/favicon-16x16.png" type="image/x-icon" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-dark" id="mainNav">
<div class="container">
<a class="navbar-brand" href="#">
<img src="/images/Semicolon Angel Corral Nunez Logo/Semicolon Only/Semicolon Color logo - no background.png"
height="60" alt="Logo image of a semi-colon">
<span class="ms-4 ms-md-3 fs-2">Soda Pop</span>
</a>
<!-- Mobile hamburger menu button -->
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="text-info">
<i class="bi bi-list"></i>
</span>
</button>
<div class="collapse navbar-collapse acn-secondary-color" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link fs-5" href="/index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link fs-5" href="/app.html">The App</a>
</li>
<li class="nav-item">
<a class="nav-link active fs-5" href="/code.html">The Code</a>
</li>
<li class="nav-item">
<a class="nav-link fs-5" target="_blank" href="https://github.com/angelcorralnunez/Soda-Pop">The Repo</a>
</li>
<li class="nav-item">
<a class="nav-link fs-5" target="_blank" href="https://angelcorralnunez.netlify.app/">About</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<main class="container mt-3">
<h1 id="code-title" class="display-5 border-bottom border-2 border-info fw-bold mb-3 mb-md-4">The Code</h1>
<h2 class="lead fw-bold">See the example code block below for the actual Javascript code used to build this app.</h2>
<div class="row">
<div class="col-lg-8 col-12">
<pre class="line-numbers">
<code class="language-js">
// get the start and end numbers from the page
// Entry point of application AKA Controller function
function getValues() {
// declared that below variables are to to pull and "hold" string values from HTML user input
let sodaNumber = document.getElementById('sodaNumber').value; // ex: sodaNumber = '3' from user/HTML
let popNumber = document.getElementById('popNumber').value; // ex: popNumber = '5' from user/HTML
let endNumber = document.getElementById('endNumber').value; // ex: endNumber = '45' from user input/HTML
let sodaNum = parseInt(sodaNumber);
let popNum = parseInt(popNumber);
let endNum = parseInt(endNumber);
// checks that all number values given by user are valid integers,
if (Number.isInteger(sodaNum) && Number.isInteger(popNum) && Number.isInteger(endNum)) {
// if variables sodaNum, popNum,and endNum are integers, it's true,
// and will generate numbers and store them in array 'numberArray'
let numberArray = generateNumbers(sodaNum, popNum, endNum);
// if it's not a number (NaN), it's false, will display error msg
displayNumbers(numberArray);
} else {
// display an error
Swal.fire({
icon: 'error',
title: 'Oops!',
text: 'Please enter valid numbers.',
backdrop: false
});
}
}
// generate the range of numbers to display
// Business/logic function
function generateNumbers(sodaNum, popNum, endNum) {
// declare empty new array 'basketOfNumbers'
// to hold values for use in the for loop below
let basketOfNumbers = [];
// for loop starts at integer at index position 1
// since 'endNum' is at index position 0, and already
// in use and accounted for inside the for loop,
// for loop keeps running until the conditions
// of the else if statement below are met
for (let i = 1; i <= endNum; i = i + 1) {
// if the current index in array basketOfNumbers
// is divisible by sodaNum & popNum,
// the index integer is removed from the array
// and replaced with the string 'Soda Pop'
if (i % sodaNum == 0 && i % popNum == 0) {
basketOfNumbers.push('Soda Pop');
// if the current index in array basketOfNumbers
// is divisible by sodaNum,the index integer
// is removed from the array and
// replaced with the string 'Soda'
} else if (i % sodaNum == 0) {
basketOfNumbers.push('Soda');
// if the current index in array basketOfNumbers
// is divisible by popNum,the index integer
// is removed from the array and
// replaced with the string 'Pop'
} else if (i % popNum == 0) {
basketOfNumbers.push('Pop');
// otherwise it replaces the integer with
// itself, integer is unchanged in array
} else {
basketOfNumbers.push(i);
}
}
// since for loop is no longer running, the
// return statement immediately exits a function,
// returning or passing back the value of the
// expression that follows to be stored in
// the array 'basketOfNumbers'
return basketOfNumbers; // => [0, 2, 3,..., 100]
}
// placing the generated numbers on the page
// View function
function displayNumbers(numbers) { //[0, 2, 3,..., 100] => length = example: 101 digits or spaces
let results = '';
// for loop adds 1 to index number, then calculates if index numbner is divisible by 2,
// if remainder equals "0" exactly, it's a match it applies the evenNumber CSS class style
// coloring the even integers,else/otherwise it returns the (odd) integers with oddNumber
// class style coloring applied.
for (let index = 0; index < numbers.length; index = index + 1) {
let currentNumber = numbers[index];
// for remaining numbers not divisible by 3, 5, or both -
// if condition of divisible by 2 is met, below css class
// styling of green is applied to the even number table data
// and if not - the remaining numbers including numbers
// divisible by 3, 5, or both - showing as 'soda,' 'pop,'
// or 'soda pop', are displayed in gray
if (currentNumber % 2 == 0) {
results = results + `<tr><td class="evenNumbers">${currentNumber}</td></tr>`;
} else {
results = results + `<tr><td class="remainingNumbers">${currentNumber}</td></tr>`;
}
}
// results are passed back into HTML ID "results"
// and displayed inside the table
let tableBody = document.getElementById('results');
tableBody.innerHTML = results;
}
</code>
</pre>
</div>
<div class="co-lg-4 col-12 my-4">
<h3 class="text-bs-purple fw-bold lead">The code is structured in three functions.</h3>
<h4 class="text-dark fw-bold">displayMessage</h4>
<h5 class="text-dark fw-bold">prints out the message</h5>
</div>
</div>
</main>
</body>
<footer class="py-3">
<div class="container">
<div class="row row-cols-1 row-cols-lg-3 align-items-center">
<div class="col text-center text-lg-start">
© 2023 Angel Corral Nunez
</div>
<div class="col text-center">
<img src="/images/Angel Single Semicolon Logo/Logo Files/For Web/svg/Color logo - no background.svg"
height="48" width="350"alt="Logo image of name 'Angel Corral Nunez'"/>
</div>
<div class="col text-center text-lg-end">
<a target="blank" href="https://www.linkedin.com/in/angelcorralnunez/">
<i class="socialicons bi bi-linkedin px-1"
alt="Icon for link to the 'Linkedin' professional
social network profile for Angel Corral Nunez."></i></a>
<a target="blank" href="https://github.com/angelcorralnunez">
<i class="socialicons bi bi-github px-1"
alt="Icon for link to the'Github'code hosting platform
account for Angel Corral Nunez."></i></a>
</div>
</div>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous">
</script>
<script src="/js/prism.js"></script>
<!-- formats code blocks -->
<script>
Prism.plugins.NormalizeWhitespace.setDefaults({
'remove-trailing': true,
'remove-indent': true,
'left-trim': true,
'right-trim': true
})
</script>
</html>