-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.html
220 lines (180 loc) · 8.28 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
<!doctype html>
<html lang="en" class="h-100">
<head>
<title>FizzBuzz: A Coding Project By Casey Spaulding</title>
<!-- 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">
<!--FONT AWESOME-->
<link href="/vendor/fontawesome6/css/fontawesome.css" rel="stylesheet">
<link href="/vendor/fontawesome6/css/brands.css" rel="stylesheet">
<link href="/vendor/fontawesome6/css/solid.css" rel="stylesheet">
<!--CSS-->
<link rel="stylesheet" href="css/prism.css">
<link rel="stylesheet" href="css/site.css">
<link rel="icon" type="image/png" href="img/favicon-32x32.png">
<!-- FAVICON============================== -->
<link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
<link rel="manifest" href="/img/site.webmanifest">
<link rel="mask-icon" href="/img/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="/img/favicon.ico">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="/img/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
</head>
<body class="d-flex flex-column h-100">
<!-- ==== Nav Section ===== -->
<nav class="navbar navbar-expand-md fixed-top navbar-dark bg-info">
<div class="container-fluid">
<a class="navbar-brand" href="#"><img src="img/LOGO_cs_white_only_crop.png" class="d-inline-block align-text-top"
alt="Casey Spaulding Logo" width="37" height="28"> FizzBuzz </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" href="https://github.com/caseyspaulding/FizzBuzz">Git Repo</a>
</li>
<li class="nav-item">
<a class="nav-link" target="_blank" rel="noopener noreferrer" href="https://www.caseyspaulding.com">About</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- ==== Main Section ===== -->
<main class="flex-shrink-0">
<div class="container py-4 px-5 mt-5">
<h2 class="boarder-1 border-bottom border-dark">The Code for FizzBuzz.</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 values from the user. We need to get the fizz and the buzz value.
function getValues(){
//get the user values from the page
let fizzValue = document.getElementById("fizzValue").value;
let buzzValue = document.getElementById("buzzValue").value;
//parse for numbers
fizzValue = parseInt(fizzValue);
buzzValue = parseInt(buzzValue);
//check that the numbers are integers
if(Number.isInteger(fizzValue) && Number.isInteger(buzzValue)){
//we need to call fizzBuzz
let fbArray = fizzBuzz(fizzValue, buzzValue);
//we need to call displayNumbers
displayData(fbArray);
} else{
alert("You must enter integers");
}
}
// do fizz buzz
function fizzBuzz(fizzValue, buzzValue)
{
//init the returnArray
let returnArray = [];
//loop from 1 to 100
for (let i = 1; i <= 100; i++){
//check to see if divisible by both 3 and 5.
//check to see if divisible by fizz value (3)
//check to see if divisible by buzz value (5)
if(i % fizzValue == 0 && i % buzzValue == 0){
returnArray.push('FizzBuzz')
}else if (i % fizzValue == 0) {
returnArray.push('Fizz');
}else if (i % buzzValue == 0) {
returnArray.push('Buzz');
} else {
returnArray.push(i);
}
}
return returnArray;
}
//loop over the array and create a tablerow for each item.
function displayData(fbArray){
//get the table body element from the page
let tableBody = document.getElementById("results");
//get the template row
let templateRow = document.getElementById("fbTemplate");
//clear the table first
tableBody.innerHTML = "";
for (let index = 0; index < fbArray.length; index += 5) {
let tableRow = document.importNode(templateRow.content, true);
//grab the td to put into array
let rowCols = tableRow.querySelectorAll("td");
rowCols[0].classList.add(fbArray[index]);
rowCols[0].textContent = fbArray[index];
rowCols[1].classList.add(fbArray[index + 1]);
rowCols[1].textContent = fbArray[index+1];
rowCols[2].classList.add(fbArray[index + 2]);
rowCols[2].textContent = fbArray[index+2];
rowCols[3].classList.add(fbArray[index + 3]);
rowCols[3].textContent = fbArray[index+3];
rowCols[4].classList.add(fbArray[index + 4]);
rowCols[4].textContent = fbArray[index+4];
tableBody.appendChild(tableRow);
}
//add all the rows to the table.
}
</code>
</pre>
</div>
<div class="col-lg-4">
<p></p>
<h5>Summary</h5>
<p>This was a good challenge and practice getting my head around using loop statements, modulus, boolean logic, to change the data in a array.</p>
</div>
</div>
</div>
</main>
<!-- ==== Footer Section ===== -->
<footer class="footer sticky-footer mt-auto py-2 text-white bg-info">
<div class="container-fluid">
<div class="row row-cols-1 row-cols-lg-3">
<div class="col order-last order-lg-first text-white bg-info gy-2">
<div class="col py-1">© 2022 Casey Spaulding | casey.spaulding@me.com</div>
</div>
<div class="col d-flex align-items-center justify-content-center-start justify-content-lg-center">
<img src="/img/topLogoSig.png" alt="Casey Spaulding Logo">
</div>
<div class="col d-flex align-items-center justify-content-start justify-content-lg-end">
<div class="row">
<div class="col social"><a href="https://www.linkedin.com/in/caseyspaulding/"><i class="fa-heart fab fa-linkedin fa-2x"></i></a></div>
<div class="col social"><a href="http://www.github.com/caseyspaulding/"><i class="fa-heart fab fa-github fa-2x"></i></a></div>
<div class="col social"><a href="https://twitter.com/caseyspauldingg/"><i class="fa-heart fab fa-twitter fa-2x"></i></a></div>
<div class="col social"><a href="https://www.youtube.com/channel/UC5bLstR32GMs08BsNu_s5xg"><i class="fa-heart 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>