Skip to content

Commit

Permalink
+Added new project ISBN Verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
CalGrimes committed Jun 25, 2021
1 parent 026b367 commit 6e0cf05
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 20 deletions.
Binary file modified .vs/CalGrimes-Blog-Postings/v16/.suo
Binary file not shown.
5 changes: 3 additions & 2 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"",
"\\js",
"\\projects",
"\\_data",
"\\_includes"
"\\_includes",
"\\_includes\\layouts"
],
"SelectedNode": "\\_includes\\layouts\\base.njk",
"PreviewInSolutionExplorer": false
}
Binary file modified .vs/slnx.sqlite
Binary file not shown.
1 change: 1 addition & 0 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ligit nk="nk" rel="alternate" href="{{ metadata.jsonfeed.path | url }}" type="application/json" title="{{ metadata.title }}">

<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>

</head>
<body>
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion _includes/layouts/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: layouts/base.njk
templateClass: tmpl-post
---
<div class="text-center">
<h1>{{ title }}</h1>
<h1>Cal Grimes' Blog</h1>
<hr>
<br>
</div>
Expand Down
19 changes: 4 additions & 15 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,6 @@ footer > .container {
padding: 0;
}

.postlist-item {
display: flex;
flex-wrap: wrap;
align-items: baseline;
counter-increment: start-from -1;
line-height: 1.8;
}

.postlist-item:before {
display: inline-block;
pointer-events: none;
Expand Down Expand Up @@ -296,9 +288,6 @@ a[href].post-tag:visited {
background-color: var(--lightgray);
}

.postlist-item > .post-tag {
align-self: center;
}

/* Warning */
.warning {
Expand Down Expand Up @@ -335,6 +324,7 @@ a[href].direct-link:visited {
font-size: 18px;
}


/* contact page form */

.form-signin {
Expand All @@ -349,10 +339,6 @@ a[href].direct-link:visited {
}
}

/* Type */
.main-text {
font-size: 18px;
}

/* contact page form */

Expand Down Expand Up @@ -450,6 +436,9 @@ a[href].direct-link:visited {
color: var(--darkgray);
box-shadow: 0 0px 30px var(--darkgray);
}
#isbnNo{
width: 100%;
}
/* Countdown timer */
.timer {
display: flex;
Expand Down
1 change: 1 addition & 0 deletions index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ eleventyNavigation:
<p>I am a student Software Enigneer studying at Liverpool John Moores University.</p>
<p>This blog is a live project while I'm on the JAMstack bootcamp and is used to evidence my completed tasks and any extra learning that I will undertake throughout the course, Technologies user on this course are: <b>HTML, CSS, JavaScript, CMS, Bootstrap, Eleventy, Nunjucks and Markdown.</b>
</p>
You are welcome to visit my GitHub profile <a href="https://github.com/CalGrimes1"><b>HERE</b></a>
</div>
<div class="col-md">
{% set maxPosts = collections.posts.length | min(3) %}
Expand Down
103 changes: 102 additions & 1 deletion js/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,106 @@ document.getElementById("calculate").onclick = function () {
calculateTip();
};
// Tip Calculate ends here
//-------------------------

//ISBN Verifier starts here

//ISBN form properties
document.getElementById("isbnNo").oninput = function () {
switch (document.getElementById("isbnNo").value.length) {
case (1):
document.getElementById("isbnNo").value += "-";
break;
case (5):
document.getElementById("isbnNo").value += "-";
break;
case (11):
document.getElementById("isbnNo").value += "-";
break;
}

}
document.getElementById("validityDisplay").style.display = "none";

//ISBN verification starts here

//Remove occurances of "-"
function IsbnDeparation(isbn) {
return isbn.replace(/-/g, '');
}
function verifyCharacterX(isbn) {
if (isbn[isbn.length - 1] === 'X') {
return true;
}
return false;
}

//Check for invalid characters
function verifyInvalidCharacters(isbn) {
if (isbn.match(/[a-zA-Z]/g)) {
if (verifyCharacterX(isbn)) {
return false;
}
return true;
}
}

//If last position of isbn is X then replace with 10
function replaceXto10(isbn) {
return isbn[isbn.length - 1] = 10;
}

function convertsStringToNumbers(isbn) {
isbn = isbn.split('');
return isbn.map(value => Number(value));
}

//postions 0-9 multiplied by 10-1 respectively and added
function sumAndMultiplicationRecursive(isbn, index, counter) {
if (counter === 1)
return isbn[index] * counter;

return isbn[index] * counter + sumAndMultiplicationRecursive(isbn, ++index, --counter);
}

//final part of ISBN formula mod 11. If the result is 0. The ISBN is valid
function isValidIsbn(isbn) {
if (isbn % 11 === 0)
return true;

return false;
}

function verifyISBN() {
//Get user input
isbnNo = document.getElementById("isbnNo").value;

//Removing occurances of "-"
isbnNo = IsbnDeparation(isbnNo);

//Check there is no invalid charcters
if (verifyInvalidCharacters(isbnNo)) {
return false;
}

//Check if check digit is 10 (X)
if (verifyCharacterX(isbnNo)) {
replaceXto10(isbnNo);
}

isbnNo = convertsStringToNumbers(isbnNo);

return isValidIsbn(sumAndMultiplicationRecursive(isbnNo, 0, isbnNo.length));
}

document.getElementById("verify").onclick = function () {
document.getElementById("validityDisplay").style.display = "block";
if (verifyISBN())
document.getElementById("valid").innerHTML = "Valid ISBN";
else
document.getElementById("valid").innerHTML = "Invalid ISBN";
}
//ISBN Verifier ends here
// ------------------------


// ---------------------------------------------------------------------------------------
21 changes: 20 additions & 1 deletion projects/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,26 @@ eleventyNavigation:
</div>
</form>
</div>
</div>
<!-- Tip Calculator Ends here -->
<div class="col-lg-4">
<form class="form-control form-signin">
<h2>ISBN Verifier</h2>
<p>Enter an ISBN-10 numeric identifier including a final check digit at the end.</p>
<hr>
<label>ISBN Identifier
<br>Example: 3-598-21508-8
<span class="inline">
<input id="isbnNo" type="text" maxlength= "13" placeholder="ISBN Identifier">
</span>
</label>
<button class="btn" type="button" id="verify">Verify!</button>
<div id="validityDisplay">
<h5 id="valid">Invalid</h5>
</div>
</form>
</div>
</div>

<!-- JavaScript Projects ends here -->

<script src="/js/projects.js"></script>

0 comments on commit 6e0cf05

Please sign in to comment.