-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.html
216 lines (180 loc) · 10.5 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
<!doctype html>
<html lang="en">
<head>
<title>APP Name: A coding challenge</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-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<!-- Bootstrap icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<!-- Dev Icons -->
<link rel="stylesheet" type='text/css' href="https://cdn.jsdelivr.net/gh/devicons/devicon@latest/devicon.min.css" />
<!-- Prism CSS -->
<link rel="stylesheet" href="/css/prism.css">
<!-- Custom Themes -->
<link rel="stylesheet" href="/css/themes.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="/css/site.css">
</head>
<body class="" data-ad-theme="orange">
<header>
<nav class="navbar navbar-expand-lg navbar-dark">
<div class="container-xxl">
<a class="navbar-brand" href="#"> <img src="/img/mark_dark.svg" alt="Logo" height="30" class="me-3" />App name</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" 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" href="/code.html">The Code</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">The Repo</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<main class="container-xxl py-3 mt-3">
<h1 class="border-bottom border-dark">The Code</h1>
<div class="row">
<!-- The Code Example -->
<div class="col-12 col-lg-8">
<pre class="line-numbers">
<code class="language-js">
// User will use an imput to call this function and the input value will be check to see if the input
// is a palindrome, then inform the user of the findings.
function getValues() {
// Get the values from HTML and stage it for use by other functions
let originalInputString = document.getElementById('originalInputString').value;
// create a var and lowercase and replace all chars that are ^... with nothing. removing all char except the ones i expect
normalizedString = originalInputString.toLowerCase().replace(/[^a-zA-Z0-9]/g, '');
// pass the normalized string to be reversed and validated if its a palindrome
let checkedResults = checkForPalindrome(normalizedString);
// Pass bool results for is a palindrome checker and the un-normalized input from html
displayResults(checkedResults, originalInputString);
}
// is the value passed in a palindrome?
// Step 1: Reverse the string
// Step 2: Compare reversed string against original to validate they match
// Step 3: Check for error cases
// Step 4: Return if the value was a palindrome or not.
function checkForPalindrome(normalizedString){
// var for storing the input string value in reverse
let reversedString = '';
// var for storing true/false for if the input is a palindrome
let isValidPalindrome = '';
// make a for loop that reverses the string
for (let i = normalizedString.length-1;i >= 0;i--) {
reversedString += normalizedString[i];
}
// Validate the results against the normalized string and check against empty strings
if (normalizedString == reversedString && normalizedString != "") {
isValidPalindrome = true;
} else {
isValidPalindrome = false;
}
return isValidPalindrome;
}
function displayResults(checkedResults, originalInputString) {
if (checkedResults == true) {
swal.fire({
background: "#dde6f4",
title: 'Good Job!',
backdrop: false,
text: `"${originalInputString}" is a Palindrome`
});
} else {
swal.fire({
icon:'error',
background: "#f8d8db",
title: 'Oops!',
backdrop: false,
text: `"${originalInputString}" is NOT a Palindrome`
});
}
}
</code>
</pre>
</div>
<!-- The Code's Explination -->
<div class="col-12 col-lg-4">
<h4>Code Structure</h4>
<p>
The code is structured into 3 functions that store the input from the user and
run some code to determine if their input has the same value forwards as backwards.
</p>
<h5>The entry point:</h5>
<h5 class="pb-3"><code>function getValues()</code></h5>
<h5>Function 1:</h5>
<p>
The <code>getValues</code> function takes the
value from the input, parses the data properly for use and uses that value
to go through a series of functions to check if the value is or is not a
palindrome.
</p>
<h5>Function 2:</h5>
<p>
The <code>checkForPalindrome</code> function takes the normalized value from
<code>getValues</code> and creates a copy of that string, reverses that string,
and then compare that reversed string to the normalized string to confirm it
is a palindrome. Once we have discovered if the input is the a palindrome that
information is returned back to <code>getValues</code>.
</p>
<h5>Function 3:</h5>
<p>
The <code>displayResults</code> function takes all the data we collect and uses
that data to create a message that will display seemlessly to the user. That
message is a javascript alert decorated using SweetAlert2
<a href="https://sweetalert2.github.io/" class="text-decoration-none" target="_blank">link</a>.
</p>
</div>
</div>
</main>
<footer class="container-fluid py-3">
<div class="container-xxl">
<div class="row align-items-center row-cols-1 row-cols-lg-3 gy-2">
<div class="col order-last order-lg-first text-center text-lg-start">
© 2024 Austin Denofrio
</div>
<div class="col text-center">
<a href="https://denofrio-fullstack-developer.netlify.app/" target="_blank"><img src="/img/signature_dark.svg" height="30" alt="Logo" /></a>
</div>
<div class="col text-center text-lg-end">
<a class="text-decoration-none" target="_blank" href="https://www.linkedin.com/in/austin-denofrio-286792223/" ><i class="bi bi-linkedin"></i></a>
<a class="text-decoration-none" target="_blank" href="https://github.com/AustinAdamDenofrio" ><i class="bi bi-github"></i></a>
<a class="text-decoration-none" target="_blank" href="https://twitter.com/A_Denofrio" ><i class="bi bi-twitter-x"></i></a>
<a class="text-decoration-none" target="_blank" href="mailto:[email protected]" ><i class="bi bi-envelope-at-fill"></i></a>
</div>
</div>
</div>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
<!-- Prism JS -->
<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>