Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Sprint-1/destructuring/exercise-1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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}.`
);
Expand Down
24 changes: 24 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,27 @@ let hogwarts = [
occupation: "Teacher",
},
];

function nameAndHoues(arr) {
let namesOfGryffindor = "";
for (pepole of hogwarts) {
const { firstName, house, lastName } = pepole;
if (house === "Gryffindor") {
namesOfGryffindor += `${firstName} ${lastName}\n`;
}
}
return namesOfGryffindor;
}

function staffPets(arr) {
let namesOfTeachersPets = "";
for (let i = 0; i < arr.length; i++) {
const { firstName, pet, occupation, lastName } = arr[i];
if (occupation == "Teacher" && pet !== null)
namesOfTeachersPets += `${firstName} ${lastName}`;
}
return namesOfTeachersPets;
}

console.log(nameAndHoues(hogwarts));
console.log(staffPets(hogwarts));
22 changes: 22 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,25 @@ let order = [
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
];

function receipt(arr) {
let totalPrice = 0;
let subTotal = 0;
let totals = "";
for (let i = 0; i < order.length; i++) {
const { itemName, quantity, unitPricePence } = arr[i];

subTotal = unitPricePence * quantity;
let unitPricePenceAsCash = unitPricePence / 100;
unitPricePenceAsCash = unitPricePenceAsCash.toFixed(2);
totalPrice += subTotal;

totals = quantity + itemName + unitPricePenceAsCash;
// totals = `${quantity} ${itemName} ${unitPricePenceAsCash}`

console.log("%c", totals);
}

console.log(` total ${totalPrice}`);
}
console.log(receipt(order));
89 changes: 56 additions & 33 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,49 @@ window.addEventListener("load", function (e) {
render();
});




function populateStorage() {
if (myLibrary.length == 0) {
if (myLibrary.length === 0) {
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
let book2 = new Book(
"The Old Man and the Sea",
"Ernest Hemingway",
"127",
true
);
myLibrary.push(book1);
myLibrary.push(book2);
render();
"Ernest Hemingway", "5", true);
myLibrary.push(book1, book2);


render();
}
}

const title = document.getElementById("title");
const author = document.getElementById("author");
const pages = document.getElementById("pages");
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() {
const title = document.getElementById("title").value;
const author = document.getElementById("author").value;
const pages = document.getElementById("pages").value;
const check = document.getElementById("check").checked;
if (
title.value == null ||
title.value == "" ||
pages.value == null ||
pages.value == ""
) {

title == "" ||
pages == ""||
author == ""
)

{
alert("Please fill all fields!");
return false;
return true;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
let book = new Book(title, author, pages, check);
myLibrary.push(book);
render();
//clear the input values


}
}

Expand All @@ -54,12 +62,17 @@ 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
let length = myLibrary.length;
for (let i = 0; i < length; i++) {
let length = myLibrary.length ;
for (let i = 0; i <= length; i++) {

let row = table.insertRow(1);
let titleCell = row.insertCell(0);
let authorCell = row.insertCell(1);
Expand All @@ -69,35 +82,45 @@ function render() {
titleCell.innerHTML = myLibrary[i].title;
authorCell.innerHTML = myLibrary[i].author;
pagesCell.innerHTML = myLibrary[i].pages;

//deleteCell.innerHTML = delBut[i]




//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";
}
changeBut.innerText = readStatus;

changeBut.addEventListener("click", function () {
myLibrary[i].check = !myLibrary[i].check;
render();
});

if( myLibrary[i].check == true){
myLibrary[i].check = false;
}
else {
myLibrary[i].check = true;
}

render();
});
//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
let delBut = document.createElement("button");
delBut.id = i ;
deleteCell.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();
});
})};
}
}
9 changes: 9 additions & 0 deletions debugging/code-reading/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Take a look at the following code:
```

Explain why line 5 and line 8 output different numbers.
line 5 logs the "let x" from the local scope of the function
where as line 8 uses the "let x" from line one in the global scope

## Question 2

Expand All @@ -34,6 +36,13 @@ console.log(y);
```

What will be the output of this code. Explain your answer in 50 words or less.
you will get
10
undefined
undefined
the x is in the global scope so accsesable to f1
f1 has no return value to log
and the y is only in the local scope of the function

## Question 3

Expand Down
5 changes: 5 additions & 0 deletions hahaha/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<html>
<head> </head>
<body> </body>
</html>
Empty file added hahaha/script.js
Empty file.
Empty file added hahaha/style.css
Empty file.