Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Bashir week 5 #1012

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d0eb2ef
added notes to w2-j4
Ashaghel Apr 26, 2020
c30ee0f
Hakona Matata Anthony and Ahmad
Ashaghel Apr 26, 2020
74e3f46
fix minor spelling and grammatical errors
Apr 27, 2020
6fcaeb5
editing exercises for week3 mcr3
Ashaghel May 1, 2020
468db41
Update 5-journey-planner.js
Ashaghel May 2, 2020
6163944
Update 0- Introduction.md
Ashaghel May 2, 2020
9346bcb
added info on every and some to exercise 2
Augs0 May 2, 2020
960c002
fixed formatting
Augs0 May 2, 2020
c5786a9
added info on replace and substring
Augs0 May 2, 2020
eb54bc5
Modify description and add extra tests to exercise week-3/4-eligible-…
zoltan-gal May 2, 2020
191b122
fix syntax
zoltan-gal May 2, 2020
e20bef6
Add extra exercise to week-3/4-eligible-students
zoltan-gal May 2, 2020
7905332
added small note
Ashaghel May 2, 2020
6c489f4
Added more instructions
Ashaghel May 2, 2020
ce4cdb0
changed function name
Ashaghel May 2, 2020
46747c0
Update 6-lane-names.js
Ashaghel May 2, 2020
1422133
formating
Ashaghel May 2, 2020
4feab6b
Add more details and restructure journey planner exercise
zoltan-gal May 2, 2020
349fee5
Reformatting journey planner description
zoltan-gal May 2, 2020
fe6726a
Add extra challange tip to journey planner
zoltan-gal May 2, 2020
9678006
Add examples and tweak descriptions
zoltan-gal May 2, 2020
222a34b
tweak week-3 intro description
zoltan-gal May 2, 2020
ccc11b5
tweak week-3 intro description
zoltan-gal May 2, 2020
7a91d2e
fix text
zoltan-gal May 2, 2020
1a7abaf
Improve examples in ex4
zoltan-gal May 2, 2020
e84f22f
Merge remote-tracking branch 'origin/master' into manchester3
zoltan-gal May 15, 2020
f8f41b0
more info
Ashaghel May 16, 2020
68f6d79
Create forinLoop.js
Ashaghel May 16, 2020
57dc8b0
Select freecodecamp resource list
zoltan-gal May 16, 2020
891b2aa
Add extra exercise and description to writers exercise
zoltan-gal May 16, 2020
e50722e
Add extra exercises to water bottle exercise
zoltan-gal May 16, 2020
02492c9
Remove extra resources recommendations that have not been taught yet
zoltan-gal May 16, 2020
394aab1
Merge branch 'manchester3' of github.com:CodeYourFuture/js-exercises …
zoltan-gal May 16, 2020
1feffbe
Rewrite grocery list exercise
zoltan-gal May 16, 2020
4a1fa48
Fix week-4 exercise issues
zoltan-gal May 16, 2020
a3c1d0c
more reading
Ashaghel May 16, 2020
393cab1
Update 1-freecodecamp.md
Ashaghel May 16, 2020
05218bc
Update extra-homework.md
Ashaghel May 16, 2020
f836b89
Update 1-freecodecamp.md
Ashaghel May 16, 2020
90f6f0b
Update 1-freecodecamp.md
Ashaghel May 16, 2020
a4055ca
Update 1-freecodecamp.md
Ashaghel May 16, 2020
e559c9a
Update 2-writers.js
Ashaghel May 16, 2020
9b87a3e
fix description
zoltan-gal May 17, 2020
793cd96
tweak description
zoltan-gal May 17, 2020
1d25f8e
Update 2-writers.js
May 19, 2020
55efde1
fix wording
zoltan-gal May 20, 2020
27ce362
Rewrite week-5/2-exercises
zoltan-gal May 29, 2020
f555e27
Rewrite week-5/3-project
zoltan-gal May 29, 2020
6053f8e
tweak khanakademy hw descriptions
zoltan-gal May 29, 2020
37bc38e
add extra description to week-5, exercise 3
zoltan-gal May 30, 2020
6409675
fix link
zoltan-gal May 31, 2020
94bce3f
Update exercises.js
bash93 Jun 12, 2020
b624352
Update main.js
bash93 Jun 12, 2020
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
62 changes: 44 additions & 18 deletions week-5/Homework/mandatory/2-exercises/exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
*/
// LEAVE YOUR ANSWER HERE (THIS IS OPTIONAL)


/**
* This function recieves a lists of people. Each object should contain the name and the occupation of a person.
* Look for usage of the function in the code and see what variable is passed into it as an argument.
*
*
* Create and insert the below HTML elements to the DOM for each of Objects in the Array as follows:
* 1. Add a <h1> tag to the website containing the name of the person
* 2. Add a <h2> tag to the website containing the job of the person
*
* All of your HTML elements should go inside the Div tag with the id "content".
*
*
* An example "content" div should look like:
* <div id="content">
* <h1>Mario</h1>
Expand All @@ -40,41 +39,68 @@
function insertPeopleData(arrayOfPeople) {
let content = document.querySelector("#content");
//Write your code in here
arrayOfPeople.forEach(function (person) {
let h1 = document.createElement("h1");
let h2 = document.createElement("h2");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Bashir - this is looking good at the moment.

content.appendChild(h1).textContent = person.name;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would advise putting stuff like this onto separate lines for clarity.

Suggested change
content.appendChild(h1).textContent = person.name;
h1.textContent = person.name;
content.appendChild(h1);

content.appendChild(h2).textContent = person.job;
});
}

/**
*
* Create a list of shopping items using an unordered HTML list.
* The input of this function is a simple Array of Strings, look for the concrete example in the code.
*
*
* All of your HTML elements should go inside the Div tag with the id "content".
*
* Hint for type of lists in HTML: https://www.w3schools.com/html/html_lists.asp
*/
function insertShoppingList(shoppingList) {
//Write your code in here
var unorderedList = document.createElement("ul");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid var keyword if you can - stick to using const or let

shoppingList.forEach((item) => {
var listItem = document.createElement("li");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listItem is an example of a good variable name - much clearer to read

listItem.innerText = item;
unorderedList.appendChild(listItem);
});
content.appendChild(unorderedList);
}

/**
* I'd like to display my three favorite books inside a nice webpage!
*
*
* Iterate through the array of books passed into this function and insert each book to page as follows:
* - Create a <ul> list and display each book details in <li> element.
* - For each book, create a <p> element with the book title and author and append it to the page.
* - Add an <img> after <p> element to each book that links to a URL of the book cover.
* You should find an appropriate image to each book.
* - Change the style of the book depending on whether you have read it (green) or not (red).*
*
*
* Find in the code what properties a book object has in the array.
*
*
* All of your HTML elements should go inside the Div tag with the id "content".
*
*
* The end result should look something like this: https://hyf-js2-week1-makeme-ex1-demo.herokuapp.com
*/
function insertBooks(books) {
//Write your code in here
let bookslist = document.createElement("ul");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good variable name

let imageList = ["./img/1.jpg", "./img/2.jpg", "./img/3.jpg"];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These images won't display anything - you might need to find some images off Google images

books.forEach((item, index) => {
let book = document.createElement("li");
if (item.alreadyRead) {
book.style.backgroundColor = "green";
} else {
book.style.backgroundColor = "red";
}
let bookName = document.createElement("p");
bookName.innerText = `${item.title}-${item.author}`;
let bookImg = document.createElement("img");
bookImg.src = imageList[i];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment there is a ReferenceError appearing in the Chrome console. It is stating that i is not defined

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try and work out where this error is coming from ?

book.appendChild(bookName);
book.appendChild(bookImg);
bookslist.appendChild(book);
});
}

//
//
//
Expand All @@ -86,9 +112,9 @@ function insertBooks(books) {
//

let people = [
{ name: "Chris", job: "Teacher" },
{ name: "Joanna", job: "Student" },
{ name: "Boris", job: "Prime Minister" }
{name: "Chris", job: "Teacher"},
{name: "Joanna", job: "Student"},
{name: "Boris", job: "Prime Minister"},
];

insertPeopleData(people);
Expand All @@ -101,18 +127,18 @@ const books = [
{
title: "The Design of Everyday Things",
author: "Don Norman",
alreadyRead: false
alreadyRead: false,
},
{
title: "The Most Human Human",
author: "Brian Christian",
alreadyRead: true
alreadyRead: true,
},
{
title: "The Pragmatic Programmer",
author: "Andrew Hunt",
alreadyRead: true
}
alreadyRead: true,
},
];

insertBooks(books);