Skip to content
Closed
4 changes: 3 additions & 1 deletion Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const personOne = {

// Update the parameter to this function to make it work.
// Don't change anything else.
function introduceYourself(___________________________) {
function introduceYourself({name, age, favouriteFood}) {
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
);
}

introduceYourself(personOne);

// the syntax to destructure is let {name,age, favouriteFood} = personOne
15 changes: 15 additions & 0 deletions Sprint-1/destructuring/exercise-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,19 @@ let hogwarts = [
pet: "Phoenix",
occupation: "Teacher",
},

];

hogwarts.forEach(({firstName,lastName,house,pet,occupation}) => {
if(house === "Gryffindor") {
console.log(`${firstName} ${lastName}`)
}
})
console.log("");

hogwarts.forEach(({firstName,lastName,house,pet,occupation}) => {
if(occupation === "Teacher" && pet) {
console.log(`${firstName} ${lastName}`)
}
})

32 changes: 16 additions & 16 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ const check = document.getElementById("check");
//check the right input from forms and if its ok -> add the new book (object in array)
//via Book function and start render function
function submit() {
if (
title.value == null ||
title.value == "" ||
pages.value == null ||
pages.value == ""
) {
if (!title.value.trim() || !author.value.trim() || !pages.value.trim()) {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
let book = new Book(title.value, author.value, pages.value, check.checked);
myLibrary.push(book);
render();
//clear user input data after storing the information
title.value = "";
author.value = "";
pages.value = "";
check.checked = false;
}
}

Expand All @@ -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
Expand All @@ -77,9 +77,9 @@ function render() {
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "Yes";
} else {
readStatus = "No";
} else {
readStatus = "Yes";
}
changeBut.innerText = readStatus;

Expand All @@ -90,11 +90,11 @@ function render() {

//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
deleteCell.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delButton.id = i + 5;
deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"homepage": "https://github.com/CodeYourFuture/Module-JS3#readme",
"devDependencies": {
"jest": "^29.5.0",
"prettier": "^2.8.7"
"prettier": "^2.8.8"
}
}