Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 +6,9 @@ const personOne = {

// Update the parameter to this function to make it work.
// Don't change anything else.
function introduceYourself(___________________________) {

let {name,age,favouriteFood} = personOne;
function introduceYourself({name,age,favouriteFood}) {
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
);
Expand Down
9 changes: 9 additions & 0 deletions Sprint-1/destructuring/exercise-2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,12 @@ let hogwarts = [
occupation: "Teacher",
},
];
function getFilteredNames(hogwarts)
{

let filterName =hogwarts.filter(({house})=>house==="Gryffindor").map(({firstName,lastName})=> `${firstName} ${lastName}`);
console.log(filterName);
let teachersWithPet = hogwarts.filter(({pet,occupation})=> pet!==null && occupation === "Teacher").map(({firstName,lastName})=>`${firstName} ${lastName}`);
console.log(teachersWithPet)
}
getFilteredNames(hogwarts);
23 changes: 23 additions & 0 deletions Sprint-1/destructuring/exercise-3/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,26 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

function printReceipt(order)
{
let sum = 0;
console.log("QTY".padEnd(5) + "ITEM".padEnd(20) + "TOTAL".padStart(10));
for (const { itemName, quantity, unitPricePence } of order) {
let paddedPrice = unitPricePence.toString().padStart(3, "0");
let pounds = paddedPrice.slice(0, 1);
let pence = paddedPrice.slice(1).padEnd(2, "0");
let total = `${pounds}.${pence}` * quantity;
let price = total.toFixed(2);
sum += total;
let result =
String(quantity).padEnd(5) + itemName.padEnd(20) + price.padStart(10);
console.log(result);
}
console.log();
return `Total: ${sum.toFixed(2)}`;

}


console.log(printReceipt(order));
4 changes: 2 additions & 2 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h1>Library</h1>
type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit();"
onclick="addBook();"
/>
</div>
</div>
Expand All @@ -77,7 +77,7 @@ <h1>Library</h1>
<th>Author</th>
<th>Number of Pages</th>
<th>Read</th>
<th></th>
<th>Delete</th>
</tr>
</thead>
<tbody>
Expand Down
28 changes: 15 additions & 13 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function populateStorage() {
);
myLibrary.push(book1);
myLibrary.push(book2);
render();

}
}

Expand All @@ -27,18 +27,20 @@ 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() {
function addBook() {
if (
title.value == null ||
title.value == "" ||
pages.value == null ||
pages.value == ""
pages.value == "" ||
author.value == null ||
author.value == ""
) {
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();
}
}
Expand All @@ -54,7 +56,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 @@ -69,14 +71,14 @@ function render() {
titleCell.innerHTML = myLibrary[i].title;
authorCell.innerHTML = myLibrary[i].author;
pagesCell.innerHTML = myLibrary[i].pages;

//add and wait for action for read/unread button
let changeBut = document.createElement("button");
changeBut.id = i;
changeBut.className = "btn btn-success";
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
if (myLibrary[i].check == true) {
readStatus = "Yes";
} else {
readStatus = "No";
Expand All @@ -90,11 +92,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;
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
Loading