From a38f2bc19f1017f41555c2debf40989c68f39b55 Mon Sep 17 00:00:00 2001 From: Rawan Almutairi Date: Fri, 16 Feb 2024 22:01:23 +0000 Subject: [PATCH] Main this is set in issues and in class now ## Learners, PR Template Self checklist - [ ] I have committed my files one by one, on purpose, and for a reason - [ ] I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK - [ ] I have tested my changes - [ ] My changes follow the [style guide](https://syllabus.codeyourfuture.io/guides/code-style-guide/) - [ ] My changes meet the [requirements](./README.md) of this task ## Changelist Briefly explain your PR. ## Questions Ask any questions you have for your reviewer. --- array-destructuring/exercise-1/exercise.js | 4 ++-- array-destructuring/exercise-2/exercise.js | 20 ++++++++++++++++++++ array-destructuring/exercise-3/exercise.js | 15 +++++++++++++++ book-library/index.html | 7 ++++--- book-library/script.js | 6 +++--- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/array-destructuring/exercise-1/exercise.js b/array-destructuring/exercise-1/exercise.js index a6eab299..49f595f6 100644 --- a/array-destructuring/exercise-1/exercise.js +++ b/array-destructuring/exercise-1/exercise.js @@ -4,9 +4,9 @@ const personOne = { favouriteFood: "Spinach", }; -function introduceYourself(___________________________) { +function introduceYourself(person) { console.log( - `Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.` + `Hello, my name is ${person.name}. I am ${person.age} years old and my favourite food is ${person.favouriteFood}.` ); } diff --git a/array-destructuring/exercise-2/exercise.js b/array-destructuring/exercise-2/exercise.js index e11b75eb..63e85946 100644 --- a/array-destructuring/exercise-2/exercise.js +++ b/array-destructuring/exercise-2/exercise.js @@ -70,3 +70,23 @@ let hogwarts = [ occupation: "Teacher", }, ]; + +function displayGryffindorNames(hogwarts) { + const gryffindorNames = hogwarts + .filter(({ house }) => house === "Gryffindor") + .map(({ firstName, lastName }) => `${firstName} ${lastName}`); + + console.log(gryffindorNames.join('\n')); +} + +displayGryffindorNames(hogwarts); + +function displayTeachersWithPets(hogwarts) { + const teacherNamesWithPets = hogwarts + .filter(({ occupation, pet }) => occupation === "Teacher" && pet) + .map(({ firstName, lastName }) => `${firstName} ${lastName}`); + + console.log(teacherNamesWithPets.join('\n')); +} + +displayTeachersWithPets(hogwarts); \ No newline at end of file diff --git a/array-destructuring/exercise-3/exercise.js b/array-destructuring/exercise-3/exercise.js index 0a01f8f0..3d7ea26b 100644 --- a/array-destructuring/exercise-3/exercise.js +++ b/array-destructuring/exercise-3/exercise.js @@ -6,3 +6,18 @@ let order = [ { itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 }, { itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 }, ]; + +function printReceipt(order) { + console.log("QTY\tITEM\t\t\tTOTAL"); + let totalCost = 0; + + order.forEach(({ itemName, quantity, unitPrice }) => { + const totalItemPrice = quantity * unitPrice; + totalCost += totalItemPrice; + console.log(`${quantity}\t${itemName}\t${totalItemPrice.toFixed(2)}`); + }); + + console.log(`\nTotal: ${totalCost.toFixed(2)}`); +} + +printReceipt(order); \ No newline at end of file diff --git a/book-library/index.html b/book-library/index.html index 23acfa71..81f81421 100644 --- a/book-library/index.html +++ b/book-library/index.html @@ -31,7 +31,7 @@

Library

Library /> Library type="checkbox" class="form-check-input" id="check" - value="" + value="read" />Read
diff --git a/book-library/script.js b/book-library/script.js index dc14a775..61d15fdd 100644 --- a/book-library/script.js +++ b/book-library/script.js @@ -37,7 +37,7 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); + let book = new Book(title.value, author.value, pages.value, check.checked); library.push(book); render(); } @@ -54,7 +54,7 @@ function render() { let table = document.getElementById("display"); let rowsNumber = table.rows.length; //delete old table - for (let n = rowsNumber - 1; n > 0; n-- { + for (let n = rowsNumber - 1; n > 0; n--) { table.deleteRow(n); } //insert updated row and cells @@ -94,7 +94,7 @@ function render() { cell5.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render();