87 lines
2.0 KiB
HTML
87 lines
2.0 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Exercise: Extracted Library Operations</title>
|
|
</head>
|
|
<body>
|
|
<h1>Exercise: Extracted Library Operations</h1>
|
|
|
|
<script>
|
|
'use strict';
|
|
|
|
const isLibraryUpdating = false;
|
|
const isUserLoggedIn = true;
|
|
const hasLibrarianPermissions = true;
|
|
const hasBookEditCapability = false;
|
|
const hasBookAccess = false;
|
|
|
|
const bookCollection = [
|
|
{
|
|
title: 'Book A',
|
|
price: 150,
|
|
quantity: 5,
|
|
},
|
|
{
|
|
title: 'Book B',
|
|
price: 250,
|
|
quantity: 0,
|
|
},
|
|
{
|
|
title: 'Book C',
|
|
price: 350,
|
|
quantity: 10,
|
|
},
|
|
];
|
|
|
|
function hasManagePermissions() {
|
|
return hasLibrarianPermissions || (hasBookEditCapability && hasBookAccess);
|
|
}
|
|
|
|
function printBookDetails(book) {
|
|
console.log(`Book Title: ${book.title}`);
|
|
|
|
if (book.price > 200) {
|
|
console.log('Book price is greater than 200.');
|
|
} else {
|
|
console.log('Book price is less than or equal to 200.');
|
|
}
|
|
|
|
if (book.quantity > 0) {
|
|
console.log('Book is available.');
|
|
} else {
|
|
console.log('Book is unavailable.');
|
|
}
|
|
|
|
console.log('---');
|
|
}
|
|
|
|
function processBookCollection(books) {
|
|
books.forEach(printBookDetails);
|
|
}
|
|
|
|
function handleLibraryOperations() {
|
|
if (isLibraryUpdating) {
|
|
console.log('Library system is currently updating.');
|
|
return;
|
|
}
|
|
|
|
if (!isUserLoggedIn) {
|
|
console.log('Please log in to manage books.');
|
|
return;
|
|
}
|
|
|
|
if (!hasManagePermissions()) {
|
|
console.log('Insufficient rights to manage books.');
|
|
return;
|
|
}
|
|
|
|
processBookCollection(bookCollection);
|
|
}
|
|
|
|
handleLibraryOperations();
|
|
</script>
|
|
</body>
|
|
</html>
|