Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Ebenezer-JS3-Wk3 #64

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ After you've watched these videos I'd like you to answer these questions

<!-- Write your answer here -->

To be a problem solver. To be able to think about a problem and come up with a solution.

## 2. When trying to solve a challenge, what should you do first?

<!-- Write your answer here -->

1. Try and understand your problem.
2. Try and visualise it and maybe do the rubber duckie thing.

## 3. What should you do if you get stuck?

<!-- Write your answer here -->

You stop and take a break and the regroup.
Talk to a rubber duckie
Research google
20 changes: 10 additions & 10 deletions week-1/Homework/mandatory/1-debugging-practice/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function submit() {
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 +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 @@ -76,25 +76,25 @@ function render() {
changeBut.className = "btn btn-success";
cell4.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
if (myLibrary[i].check === true) {
readStatus = "Yes";
} else {
readStatus = "No";
}
changeBut.innerHTML = readStatus;

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

//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
cell5.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delButton.id = i + 5;
cell5.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
27 changes: 27 additions & 0 deletions week-3/Homework/mandatory/2-exercises/1-shopping-cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*

Complete the rest of this code to create an online shopping cart.

The output of running your code should be:

Your shopping cart has 3 items: Toilet Roll, Pasta, Eggs


*/

class ShoppingCart {
// Add your code here

cartContains() {
console.log()
// Use console.log() to output everything contained in your cart
}
}

let myCart = new ShoppingCart(); // Creates an empty shopping cart

myCart.addItem("Toilet Roll");
myCart.addItem("Pasta");
myCart.addItem("Eggs");

myCart.cartContains();
16 changes: 10 additions & 6 deletions week-3/Homework/mandatory/2-exercises/exercise-1/exercise-1.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const personOne = {
name: 'Popeye',
age: 34,
favouriteFood: 'Spinach'
}
name: "Ebenezer",
age: 110,
favouriteFood: "Brocolli",
};

const { name, age, favouriteFood } = personOne;

function introduceYourself(___________________________) {
console.log (`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`);
console.log(
`Hello, my name is ${name}. I am ${age} years old and my favourite food is ${favouriteFood}.`
);
}

introduceYourself(personOne);
introduceYourself(personOne);
96 changes: 86 additions & 10 deletions week-3/Homework/mandatory/2-exercises/exercise-2/exercise-2.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,87 @@
let hogwarts = [
{ firstName: "Harry", lastName: "Potter", house: "Gryffindor", pet: "Owl", occupation: "Student" },
{ firstName: "Hermione", lastName: "Granger", house: "Gryffindor", pet: "Cat", occupation: "Student" },
{ firstName: "Draco", lastName: "Malfoy", house: "Slytherin", pet: null, occupation: "Student" },
{ firstName: "Cedric", lastName: "Diggory", house: "HufflePuff", pet: null, occupation: "Student" },
{ firstName: "Severus", lastName: "Snape", house: "Slytherin", pet: null, occupation: "Teacher" },
{ firstName: "Filius", lastName: "Flitwick", house: "Ravenclaw", pet: null, occupation: "Teacher" },
{ firstName: "Pomona", lastName: "Sprout", house: "Hufflepuff", pet: null, occupation: "Teacher" },
{ firstName: "Minerva", lastName: "McGonagall", house: "Gryffindor", pet: null, occupation: "Teacher" },
{ firstName: "Albus", lastName: "Dumbledore", house: "Gryffindor", pet: "Phoenix", occupation: "Teacher" }
]
{
firstName: "Harry",
lastName: "Potter",
house: "Gryffindor",
pet: "Owl",
occupation: "Student",
},
{
firstName: "Hermione",
lastName: "Granger",
house: "Gryffindor",
pet: "Cat",
occupation: "Student",
},
{
firstName: "Draco",
lastName: "Malfoy",
house: "Slytherin",
pet: null,
occupation: "Student",
},
{
firstName: "Cedric",
lastName: "Diggory",
house: "HufflePuff",
pet: null,
occupation: "Student",
},
{
firstName: "Severus",
lastName: "Snape",
house: "Slytherin",
pet: null,
occupation: "Teacher",
},
{
firstName: "Filius",
lastName: "Flitwick",
house: "Ravenclaw",
pet: null,
occupation: "Teacher",
},
{
firstName: "Pomona",
lastName: "Sprout",
house: "Hufflepuff",
pet: null,
occupation: "Teacher",
},
{
firstName: "Minerva",
lastName: "McGonagall",
house: "Gryffindor",
pet: null,
occupation: "Teacher",
},
{
firstName: "Albus",
lastName: "Dumbledore",
house: "Gryffindor",
pet: "Phoenix",
occupation: "Teacher",
},
];

function peopleGryffindor(arr) {
for (var i = 0; i < arr.length; ++i) {
let { firstName, lastName, house } = arr[i];
if (house === "Gryffindor") {
console.log(`${firstName} ${lastName}`);
}
}
}

peopleGryffindor(hogwarts);

function petOwners(arr) {
for (var i = 0; i < arr.length; ++i) {
let { firstName, lastName, pet, occupation } = arr[i];
if (pet !== null && occupation === "Teacher") {
console.log(`${firstName} ${lastName}`);
}
}
}

petOwners(hogwarts);
34 changes: 25 additions & 9 deletions week-3/Homework/mandatory/2-exercises/exercise-3/exercise-3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
let order = [
{ itemName: "Hot cakes", quantity: 1, unitPrice: 2.29},
{ itemName: "Apple Pie", quantity: 2, unitPrice: 1.39},
{ itemName: "Egg McMuffin", quantity: 1, unitPrice: 2.80},
{ itemName: "Sausage McMuffin", quantity: 1, unitPrice: 3.00},
{ itemName: "Hot Coffee", quantity: 2, unitPrice: 1.00},
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.40}
]

let order = [
{ itemName: "Hot cakes", quantity: 1, unitPrice: 2.29 },
{ itemName: "Apple Pie", quantity: 2, unitPrice: 1.39 },
{ itemName: "Egg McMuffin", quantity: 1, unitPrice: 2.8 },
{ itemName: "Sausage McMuffin", quantity: 1, unitPrice: 3.0 },
{ itemName: "Hot Coffee", quantity: 2, unitPrice: 1.0 },
{ itemName: "Hash Brown", quantity: 4, unitPrice: 0.4 },
];

function printReceipt(order) {
let totalPx = 0;
console.log(`QTY ITEM TOTAL`);
for (let i = 0; i < order.length; ++i) {
const { itemName, quantity, unitPrice } = order[i];
totalPx += unitPrice;
if (itemName.length > 12) {
console.log(`${quantity} ${itemName} ${unitPrice.toFixed(2)}`);
} else {
console.log(`${quantity} ${itemName} ${unitPrice.toFixed(2)}`);
}
}
console.log(`Total: ${totalPx.toFixed(2)}`);
}

printReceipt(order);