Skip to content

Commit 095567b

Browse files
committed
Review w3.org
1 parent 9c74db3 commit 095567b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

debugging/book-library/index.html

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title> </title>
5-
<meta
6-
charset="utf-8"
7-
name="viewport"
8-
content="width=device-width, initial-scale=1.0"
9-
/>
4+
<title> Book Library </title>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
108
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
119
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
1210
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
@@ -31,19 +29,17 @@ <h1>Library</h1>
3129
<div class="form-group">
3230
<label for="title">Title:</label>
3331
<input
34-
type="title"
32+
type="text"
3533
class="form-control"
3634
id="title"
3735
name="title"
38-
required
3936
/>
4037
<label for="author">Author: </label>
4138
<input
42-
type="author"
39+
type="text"
4340
class="form-control"
4441
id="author"
4542
name="author"
46-
required
4743
/>
4844
<label for="pages">Pages:</label>
4945
<input
@@ -80,15 +76,13 @@ <h1>Library</h1>
8076
<th></th>
8177
</tr>
8278
</thead>
83-
<tbody>
8479
<tr>
8580
<td></td>
8681
<td></td>
8782
<td></td>
8883
<td></td>
8984
<td></td>
9085
</tr>
91-
</tbody>
9286
</table>
9387

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

debugging/book-library/script.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,25 @@ const check = document.getElementById("check");
3131
function submit() {
3232
const cleanTitle = title.value.trim();
3333
const cleanAuthor = author.value.trim();
34-
const cleanPages = parseInt(pages.value, 10);
34+
35+
if (!/^[1-9]\d*$/.test(pages.value.trim())) { // plain positive whole numbers like 1, 25, 300 — no letters, no decimal points, no scientific notation
36+
alert("Pages must be a positive whole number without letters or symbols.");
37+
return false;
38+
}
39+
40+
const cleanPages = parseInt(pages.value.trim(), 10);
3541

3642
if (!cleanTitle|| !cleanAuthor) { // title and author doesn't allowed to contain only space characters
3743
alert("Title and Author cannot be empty or spaces only.");
3844
return false;
39-
} else if (isNaN(cleanPages) || cleanPages <= 0) { // the value of type of pages must be a integer
45+
46+
} if (isNaN(cleanPages) || cleanPages <= 0) { // the value of type of pages must be a integer
4047
alert("Pages must be a positive whole number.");
4148
return false;
42-
} else {
49+
}
4350
let book = new Book(cleanTitle, cleanAuthor, pages.value, check.checked); //// title and author be allowed to contain leading or trailing space characters, we storage using parseInt
4451
myLibrary.push(book);
45-
render();
46-
}
52+
render();
4753
}
4854

4955
function Book(title, author, pages, check) {

0 commit comments

Comments
 (0)