Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Js/core 2/week3/nihal #86

Open
wants to merge 6 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
3 changes: 3 additions & 0 deletions Week-1/Homework/mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ let writers = [
alive: true
}
];
for(let i = 0; i < writers.length; i+=1){
console.log(`Hi, my name is ${writers[i].firstName} ${writers[i].lastName}. I am ${writers[i].age} years old, and work as a ${writers[i].occupation}.`)
}

/*
If you want an extra challenge, only `console.log()` the writers that are alive.
Expand Down
9 changes: 6 additions & 3 deletions Week-1/Homework/mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ We made a start on this for you here:
let bottle = {
volume: 0,
fill: function() {
// calling this function should make you bottles volume = 100;
this.volume = 100;// calling this function should make you bottles volume = 100;
},
drink: function() {
// calling this function should decrease your bottles volume by 10;
this.volume -= 10;// calling this function should decrease your bottles volume by 10;
},
empty: function() {
// this function should return true if your bottles volume = 0
if ( this.volume === 0) {
return true;
}
return false;// this function should return true if your bottles volume = 0
}
};

Expand Down
10 changes: 7 additions & 3 deletions Week-1/Homework/mandatory/3-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
let groceriesToBuy = [];

let groceryList = {
item1: "",
item2: "",
item3: ""
item1: "Potatoes",
item2: "Orange Juice",
item3: "Rice"
};
for(let key in groceryList) {
groceriesToBuy.push(groceryList[key])
}
console.log(groceriesToBuy);
7 changes: 6 additions & 1 deletion Week-1/Homework/projects/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ cocoa

**/

let recipes = {};
let recipes = {
title: "Mole",
numberOfServings: 2,
ingredients: ["cinnamon", "cumin", "cocoa"]
};
console.log(recipes.title);
26 changes: 25 additions & 1 deletion Week-1/Homework/projects/2-reading-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,28 @@ If you read it, log a string like 'You already read "The Hobbit" by J.R.R. Tolki

**/

let books = [];
let books = [
{
title: "the Hobbit",
author: "J.R.R. Tolkien",
alreadyRead: true
},
{
title: "Harry Potter",
author: "Rowling",
alreadyRead: true
},
{
title: "Lord of the Flies",
author: "Golding",
alreadyRead: true
}
];

books.forEach(function(book) {
if (books.alreadyRead)
console.log("You ara already read " + book.title + " by " + book.author);
else {
console.log("You still need to read " + book.title + " by " + book.author);
}
});
8 changes: 7 additions & 1 deletion Week-1/InClass/A-objects-intro/exercise-part-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ Describe your own laptop as a JavaScript object

Try to think of as many properties as you can!

*/
*/
let laptpp = {
model:"Dell",
thchScreen: false,
memmory: "3gb"
}
console.log(laptop)
33 changes: 33 additions & 0 deletions Week-1/InClass/A-objects-intro/exercise-part-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,36 @@ Assign each of them to a separate variable

*/

let cat = {
coulor: "red",
name: "Shenko",
age: "3years"
}

let house = {
rooms: 3,
bathrooms: 1,
kitchen: 1,
garden: 1,
balcouny: false
}

let car = {
typeOfCar: "Toyota",
year:2017,
numberOfDoors: 5
}

let shopingList = {
item1 : "Milk",
item2 : "Hony",
item3 : "Bread",
item4 : "Potato"
}

let countriesILivedIn = {
cont1: "UK",
cont2: "Sudan",
cont3: "Qatar",
cont4: "Saudi Arabia"
}
17 changes: 9 additions & 8 deletions Week-1/InClass/A-objects-intro/exercise-part-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ The objects below have some syntax issues - try and fix them all!
*/

let kitten = {
fur colour: "orange",
age "23"
furcolour: "orange",
age: "23"
};

let laptop =
brand: "Lenovo"
ram "5GB"
let laptop = {
brand: "Lenovo",
ram: "5GB"
}

let phone = {
operating system "iOS",
operatingsystem: "iOS",
hasStylus: true,
megapixels 12
"batteryLife": "24 hours"
megapixels: 12,
batteryLife: "24 hours"
}
3 changes: 2 additions & 1 deletion Week-1/InClass/B-objects-get-set/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ let kitten = {
// YOUR CODE GOES BELOW HERE



let x = kitten.ageMonths;
console.log(x);



Expand Down
12 changes: 6 additions & 6 deletions Week-1/InClass/B-objects-get-set/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/

let phone = {
brand: 'iPhone,
model 'iPhone X'
brand: 'iPhone',
model: 'iPhone X',
launchYear: 2017,
is Unlocked: true
;
isUnlocked: true
}

let phoneBrand = phone.bbrand;
let phoneLaunchYear = phone[launchYear];
let phoneBrand = phone.brand;
let phoneLaunchYear = phone.launchYear;

// DO NOT MODIFY BELOW THIS LINE

Expand Down
5 changes: 4 additions & 1 deletion Week-1/InClass/B-objects-get-set/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
*/

// WRITE CODE BELOW THIS

let kitten = {
name: "Gilbert",
age: 3
}
// WRITE CODE ABOVE THIS

console.log(kitten.name);
Expand Down
3 changes: 2 additions & 1 deletion Week-1/InClass/B-objects-get-set/exercise-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ let dog = {

// WRITE CODE BELOW THIS LINE


dog.name = "Rex";
dog.wantsToPlay = true;

// WRITE CODE ABOVE THIS LINE

Expand Down
4 changes: 4 additions & 0 deletions Week-1/InClass/C-more-complex-objects/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ let house = {

WRITE YOUR CODE BELOW
*/
house.address = '51 Berkley Road';
house.previousOwners = ["Brian M.", "Fiona S."];
house.currentOwner.lastName = "Montgomery";
console.log(house);

// - change the address of "house" to '51 Berkley Road'
// - change the previous owners of "house" to ["Brian M.", "Fiona S."]
Expand Down
3 changes: 3 additions & 0 deletions Week-1/InClass/C-more-complex-objects/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ let newCurrentOwner = {

WRITE YOUR CODE BELOW
*/
house.currentOwner = newCurrentOwner
house.previousOwners[1] = " Stephen B."
house.isForSale = false

// - assign the value of the variable 'newCurrentOwner' as the value to the house's "currentOwner"
// - from the list of previous owners, replace only "John A." with "Stephen B."
Expand Down
6 changes: 3 additions & 3 deletions Week-1/InClass/C-more-complex-objects/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ let parkAvenueHouse = {

// returns the full name (first name + last name) of the owner of the house
function getOwnerFullName(house) {

return `${house.currentOwner.firstName} ${house.currentOwner.lastName}`
}

// returns an array of the owners' email addresses of the two houses
function getEmailAddresses(house1, house2) {

return `${house1.currentOwner.email} , ${house2.currentOwner.email}`
}

// returns the address for the cheapest house out of the two
function getCheapestAddress(house1, house2) {

return house1.price > house2.price
}


Expand Down
5 changes: 4 additions & 1 deletion Week-1/InClass/D-methods/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ Add a method "greet" so this person can say hello.

let person = {
name: "Alice",
age: 25
age: 25,
greet(){
return "Hello everybody"
}
};


Expand Down
5 changes: 4 additions & 1 deletion Week-1/InClass/D-methods/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Hint: use 'this' keyword to access the name property.

let person = {
name: "Alice",
age: 25
age: 25,
sayName: function () {
return "My name is " + this.name
}
};


Expand Down
8 changes: 4 additions & 4 deletions Week-1/InClass/D-methods/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ let person = {
name: "Alice",
age: 25,
currentAddress: "Glasgow",
changeAddress: (newAddress) {
currentAddress = newAddress;
changeAddress: function(newAddress) {
this.currentAddress = newAddress;
},
celebrateBirthday: function {
that.age = that.age + 1;
celebrateBirthday: function() {
this.age = this.age + 1;
}
};

Expand Down
5 changes: 4 additions & 1 deletion Week-1/InClass/D-methods/exercise-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ Define a method "makeFriend" to add a new friend to her list.

let person = {
name: "Alice",
friends: ["John", "Nina"]
friends: ["John", "Nina"],
makeFriend(newFriend) {
this.friends.push(newFriend)
}
};


Expand Down
15 changes: 15 additions & 0 deletions Week-1/InClass/D-methods/exercise-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@ let coffeeMachine = {
},
insertedAmount: 0,
insertMoney: function (amount) {
return this.insertedAmount = amount;
if (amount >= 1.50 && amount < 2.40) {
return this.insertedAmount;
}else if (amount >=2.40 && amount <3.00) {
return this.insertedAmount;
}else {
return this.insertedAmount;
}

},
getCoffee: function (coffee) {
if (this.insertedAmount >= 1.50 && this.insertedAmount < 2.40) {
return `Please take your ${coffee}`;
}else if (this.insertedAmount >= 2.40 && this.insertedAmount < 3.00) {
return `Plaase take your ${coffee}`;
}else {
return `Please take your ${coffee}`
}

}
};
Expand Down
6 changes: 3 additions & 3 deletions Week-1/InClass/E-arrays-of-objects/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ WRITE YOUR CODE BELOW
*/


var persons = // Complete here
var persons = [person1, person2, person3]// Complete here

var personNames = // Complete here
var personNames = persons.map(x => x.name) // Complete here

var personsYoungerThan28YearsOld = // Complete here
var personsYoungerThan28YearsOld = persons.filter(x => x.age < 28) // Complete here


/*
Expand Down
6 changes: 3 additions & 3 deletions Week-1/InClass/E-arrays-of-objects/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ WRITE YOUR CODE BELOW
*/


let destinationNamesWithin500Kms = // Complete here
let destinationNamesWithin500Kms = travelDestinations.filter(a => a.distanceKms < 500).map(b => b.destinationName);// Complete here

let destinationNameReachableByFerry = // Complete here
let destinationNameReachableByFerry = travelDestinations.find(c => c.transportations.includes(`ferry`)).destinationName;// Complete here

let destinationNamesMoreThan300KmsAwayByTrain = // Complete here (PRINT THE RESULT IN THE CONSOLE USING FOREACH)
let destinationNamesMoreThan300KmsAwayByTrain = travelDestinations.filter(a => a.distanceKms > 300).filter(c => c.transportations.includes(`train`)).map(a => a.destinationName);// Complete here (PRINT THE RESULT IN THE CONSOLE USING FOREACH)


/*
Expand Down
6 changes: 3 additions & 3 deletions Week-1/InClass/E-arrays-of-objects/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ let restaurantFinderApplication = {
applicationVersion: "1.0",
restaurants: restaurants,
findAvailableRestaurants: function (numberOfPeople) {
// Complete here
return this.restaurants.filter(x => x.totalSeats - x.numberOfCustomers >= numberOfPeople).map(x => x.name);// Complete here
},
findRestaurantServingDish: function (dishName) {
// Complete here
return this.restaurants.filter(x => x.menu.includes(dishName)).map(x => x.name); // Complete here
},
countNumberOfRestaurantsInArea: function (area) {
// Complete here
return this.restaurants.filter(x => x.address.area === area).length;// Complete here
}
};

Expand Down
4 changes: 2 additions & 2 deletions Week-1/InClass/F-object-keys/exercise-part-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ let highScores = {

// ONLY EDIT BELOW HERE

let capitalCitiesKeys = ;
let highScoresKeys;
let capitalCitiesKeys = Object.keys(capitalCities);
let highScoresKeys = Object.keys(highScores);

// ONLY EDIT ABOVE HERE

Expand Down
Loading