0 Members and 1 Guest are viewing this topic.
const library = {name: "Central City Library",location: {street: "Library Avenue 5",city: "Metropolis",state: "NY",postalCode: "10001",},books: [{bookId: "B001",title: "JavaScript: The Good Parts",author: "Douglas Crockford",genres: ["Programming", "Technology"],copies: 5,borrowed: [{ memberId: "M001", date: "2023-07-14", returned: false },{ memberId: "M002", date: "2023-07-20", returned: true },],},{bookId: "B002",title: "Clean Code",author: "Robert C. Martin",genres: ["Programming", "Best Practices"],copies: 3,borrowed: [{ memberId: "M003", date: "2023-08-01", returned: true }],},{bookId: "B003",title: "The Pragmatic Programmer",author: "Andrew Hunt",genres: ["Programming", "Development"],copies: 4,borrowed: [],},],members: [{memberId: "M001",name: "John Doe",email: "john.doe@example.com",membershipActive: true,},{memberId: "M002",name: "Jane Smith",email: "jane.smith@example.com",membershipActive: false,},{memberId: "M003",name: "Emily Johnson",email: "emily.johnson@example.com",membershipActive: true,},],
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <script src="main.js" defer></script> </head> <body></body></html>
"use strict";const library = { name: "Central City Library", location: { street: "Library Avenue 5", city: "Metropolis", state: "NY", postalCode: "10001", }, books: [ { bookId: "B001", title: "JavaScript: The Good Parts", author: "Douglas Crockford", genres: ["Programming", "Technology"], copies: 5, borrowed: [ { memberId: "M001", date: "2023-07-14", returned: false }, { memberId: "M002", date: "2023-07-20", returned: true }, ], }, { bookId: "B002", title: "Clean Code", author: "Robert C. Martin", genres: ["Programming", "Best Practices"], copies: 3, borrowed: [{ memberId: "M003", date: "2023-08-01", returned: true }], }, { bookId: "B003", title: "The Pragmatic Programmer", author: "Andrew Hunt", genres: ["Programming", "Development"], copies: 4, borrowed: [], }, ], members: [ { memberId: "M001", name: "John Doe", email: "john.doe@example.com", membershipActive: true, }, { memberId: "M002", name: "Jane Smith", email: "jane.smith@example.com", membershipActive: false, }, { memberId: "M003", name: "Emily Johnson", email: "emily.johnson@example.com", membershipActive: true, }, ], allBooksTitles: function () { return this.books.map((book) => book.title); //II nacin // function filteredByTitle(book) { // return book.title; // } // return this.books.map(filteredByTitle); }, moreThanThreeBookCopies: function (n) { // I nacin - vraca ceo obj book // return this.books // .filter((book) => book.copies > n) //I nacin - vraca samo naslove // return this.books // .filter((book) => book.copies > n) // .map((book) => book.title); //II nacin const result = []; for (let book of this.books) { if (book.copies > n) { result.push(book); } } return result; // return result.map((book) => book.title); }, isMemberActiv: function (id) { const member = this.members.find((clan) => clan.memberId === id); console.log(member); if (member) { return `Is membership active for member ${member.name}: ${member.membershipActive}`; } else { return `This member is not found!`; } }, addNewBook(bookId, title, author, genres, copies) { return this.books.push({ bookId: bookId, title: title, author: author, genres: genres, copies: copies, borrowed: [], }); }, updateBookCopies: function (id, numOfCopies) { const book = this.books.find((book) => book.bookId === id); book ? (book.copies += numOfCopies) : alert("Book is not found!"); }, transformedMembers() { return this.members.map((member) => { return { userId: member.memberId, userName: member.name, }; }); }, allBooksCopies() { // return this.books // .map((book) => book.copies) // .reduce((acc, curr) => acc + curr, 0); //II nacin let zbir = 0; for (const book of this.books) { zbir += book.copies; } return zbir; }, getAllActiveMembers: function () { return this.members .filter((member) => member.membershipActive) .map((member) => member.name); }, getAllUnreturnedBooks() { const result = []; // this.books.forEach((book) => { // if (book.borrowed.length) { // book.borrowed.forEach((obj) => { // if (!obj.returned) result.push(book.title); // }); // } // }); // return result; //II nacin for (const book of this.books) { if (book.borrowed.length) { for (const obj of book.borrowed) { if (obj.returned) { console.log(book.title, "is returned"); } else { result.push(book.title); } } } } return result; }, getLibraryInfo: function () { return { libraryName: this.name, libraryLocation: this.location, activeMembers: this.getAllActiveMembers().length, }; },};console.log(library.allBooksTitles());console.log(library.moreThanThreeBookCopies(3));console.log(library.isMemberActiv("M003"));library.addNewBook("B005", "How to write C", "John Simons", ["Programming"], 8);console.log(library);library.updateBookCopies("B002", 5);console.log(library);console.log(library.transformedMembers());console.log(library.allBooksCopies());console.log(library.getAllActiveMembers());console.log(library.getAllUnreturnedBooks());console.log(library.getLibraryInfo());
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <link rel="stylesheet" href="style.css" /> <script src="main.js" defer></script> </head> <body> <div class="container"> <h1>ToDo list</h1> <input type="text" placeholder="Enter a new task" name="task" /> <button>Add task</button> <ul></ul> </div> </body></html>
* { box-sizing: border-box;}body { background-color: rgb(125, 125, 154); display: flex; justify-content: center; align-items: center; height: 100vh;}.container { width: 40%; background-color: whitesmoke; border-radius: 10px; display: flex; flex-direction: column; align-items: center; padding: 0.5rem;}input { width: 90%; margin-bottom: 0.5rem; border-radius: 5px; padding: 0.5rem;}button { width: 90%; margin-bottom: 0.5rem; background-color: rgb(0, 129, 86); color: white; padding: 0.5rem; border: none; border-radius: 5px;}ul { width: 90%; margin: 0; padding: 0;}ul li { list-style: none; display: flex; justify-content: space-between; align-items: center;}ul li p { font-size: 12px; margin: 0;}.btnDelete { width: 50px; height: 30px; background-color: red; color: white; font-size: 12px; display: flex; justify-content: center; align-items: center;}.completed { text-decoration: line-through;}
const inputTaskElement = document.getElementsByTagName("input")[0];// console.log(inputTask);const buttonAddTask = document.getElementsByTagName("button")[0];// console.log(buttonAddTask);const ulListEl = document.getElementsByTagName("ul")[0];buttonAddTask.addEventListener("click", function (event) { const inputValue = inputTaskElement.value; // console.log(inputValue); handlerFunction(inputValue);});inputTaskElement.addEventListener("keyup", function (event) { // console.log(event.target.value); if (event.key === "Enter") { handlerFunction(event.target.value); }});function handlerFunction(valueOfInput) { if (valueOfInput) { createElement(valueOfInput); resetInput(); } else { alert("Niste uneli vrednost u input polje!"); }}function createElement(value) { const liElement = document.createElement("li"); const paragraph = document.createElement("p"); const buttonDelete = document.createElement("button"); paragraph.textContent = value; paragraph.addEventListener("click", function () { //I nacin // if (this.classList.contains("completed")) { // this.classList.remove("completed"); // } else { // this.classList.add("completed"); // } //II nacin // if (this.classList.length === 0) { // this.classList.add("completed"); // } else { // this.classList.remove("completed"); // } //III nacin this.classList.toggle("completed"); }); buttonDelete.innerText = "Delete"; buttonDelete.classList.add("btnDelete"); buttonDelete.addEventListener("click", function (event) { this.parentElement.remove(); }); liElement.appendChild(paragraph); liElement.appendChild(buttonDelete); ulListEl.appendChild(liElement);}function resetInput() { inputTaskElement.value = "";}
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <script src="main.js" defer></script> <link rel="stylesheet" href="style.css" /> </head> <body> <div class="main"> <p>UNESI SVOJ FILM</p> <input type="text" /> <div class="mainbody"> <div class="container movielist"> <h4>HOCU DA GLEDAM</h4> <ul class="wanttowatch"></ul> <button class="btnclear">CLEAR MOVIE LIST</button> </div> <div class="container watchedlist"> <h4>ODGLEDANI 😘</h4> <ul class="watched"></ul> <button class="btnclear">CLEAR WATCHED LIST</button> </div> </div> </div> </body></html>
.container { width: 50%; /* height: 60%;*/ background-color: antiquewhite; display: flex; flex-direction: column; align-items: center;}.main { width: 60vw; height: 90vh; display: flex; flex-direction: column; gap: 20px;}p { margin: 0;}.mainbody { display: flex; gap: 10px;}body { display: flex; justify-content: center; align-items: center; height: 100vh; background-color: rgb(180, 133, 224);}ul { padding: 0; margin: 0; width: 100%;}ul li { list-style: none; width: 100%; text-align: center;}.btnclear { padding: 10px; margin: 20px;}
const inputBox = document.getElementsByTagName("input")[0];console.log(inputBox);const movieList = document.getElementsByClassName("wanttowatch")[0];console.log(movieList);const watchedList = document.getElementsByClassName("watched")[0];console.log(watchedList);function createMovie(value) { const liElement = document.createElement("li");}