Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions .test-summary/TEST_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Test Summary

**Mentors**: For more information on how to review homework assignments, please refer to the [Review Guide](https://github.com/HackYourFuture/mentors/blob/main/assignment-support/review-guide.md).

### 2-Browsers - Week1

| Exercise | Passed | Failed | ESLint |
|------------------|--------|--------|--------|
| ex1-bookList | 6 | - | ✓ |
| ex2-aboutMe | 4 | - | ✓ |
| ex3-hijackLogo | 3 | - | ✓ |
| ex4-whatsTheTime | 6 | - | ✓ |
| ex5-catWalk | 5 | - | ✓ |
23 changes: 22 additions & 1 deletion 2-Browsers/Week1/assignment/ex1-bookList/index.js

Choose a reason for hiding this comment

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

Textbook solution, well done :)

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,28 @@ https://hackyourfuture.github.io/example-pages/Browsers/Week1/1-booklist/
//cspell: enable

function createBookList(books) {
// TODO your code goes in here, return the ul element
const ul = document.createElement('ul');
books.forEach((book) => {
const li = document.createElement('li');
const p = document.createElement('p');
const img = document.createElement('img');
const imgName = book.title.toLowerCase().replaceAll(' ', '_');

p.textContent = `${book.title} by ${book.author}`;
img.src = `assets/${imgName}.jpg`;
img.alt = `${book.title} cover`;

if (book.alreadyRead) {
li.style.backgroundColor = 'lightgreen';
} else {
li.style.backgroundColor = 'lightcoral';
}

li.appendChild(p);
li.appendChild(img);
ul.appendChild(li);
});
return ul;
}

function main() {
Expand Down
16 changes: 16 additions & 0 deletions 2-Browsers/Week1/assignment/ex1-bookList/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
/* Write your style here */

ul {
list-style: none;
padding: 0;
margin: 0;
}

ul li {
width: 500px;
padding: 20px;
text-align: center;
border-radius: 6px;
margin-bottom: 20px;
display: inline-block;
margin-right: 12px;
}
8 changes: 7 additions & 1 deletion 2-Browsers/Week1/assignment/ex2-aboutMe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/2-B
3. Look in the css file!
------------------------------------------------------------------------------*/

// TODO add your JavaScript code here.
const ul = document.querySelector('ul').children;
ul[0].textContent = 'Alooy';

Choose a reason for hiding this comment

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

I'm not sure I like this solution 100% .. because if the li tags in the html code would get changed (hypothetically, by say a colleague, at some later point) -- then the words would now appear in the wrong place!

Luckily, there's away to prevent this, by using the classnames (.nickname, .fav-food, hometown) to target the right li elements you want to put the words in.

Can you change this to target the li elements using their classes?

ul[1].textContent = 'Burgers';
ul[2].textContent = 'Dongen';

const arr = Array.from(ul);
arr.forEach((ele) => (ele.className = 'list-item'));
3 changes: 3 additions & 0 deletions 2-Browsers/Week1/assignment/ex2-aboutMe/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/* 3. Add a css rule for .list-item to make the color red. */
.list-item {
color: red;
}
8 changes: 7 additions & 1 deletion 2-Browsers/Week1/assignment/ex3-hijackLogo.js

Choose a reason for hiding this comment

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

I'm afraid to say I can't really check this exercise, because Google as it shows up on my computer doesn't show an img, but an svg, and also has a different alt. That being said, I'm sure your solution would not work, because the URL images.png .. would reference https://google.com/images.png, which surely doesn't exist. What's the deal here?

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/2-B
HackYourFuture logo instead.
------------------------------------------------------------------------------*/
function hijackGoogleLogo() {
// TODO your code goes in here
const logo = document.querySelector(
'img[alt="Google"], img[src*="googlelogo"]'
);

logo.src = 'images.png';
logo.srcset = 'images.png';
logo.alt = 'HackYourFuture';
}

hijackGoogleLogo();
15 changes: 13 additions & 2 deletions 2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/2-B
2. Have the function execute when it's loading in the browser.
------------------------------------------------------------------------------*/
function addCurrentTime() {
// TODO complete this function
const div = document.createElement('div');
const span = document.createElement('span');

return setInterval(function () {
const time = new Date();
const hours = String(time.getHours()).padStart(2, '0');
const minutes = String(time.getMinutes()).padStart(2, '0');
const seconds = String(time.getSeconds()).padStart(2, '0');
span.textContent = `${hours}:${minutes}:${seconds}`;
div.appendChild(span);

Choose a reason for hiding this comment

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

What's a bit strange about this solution, is that every time you update the time (every second), you also add the span to the div, and the div to the body. This in weird/incorrect/wrong. It doesn't lead to any problems though, because the DOM understands that the same element can't be added twice to the same parent, so it just skips it. But I'd rather see you only do it once, anyway, to show that you understand what you're doing :) Maybe you can fix this?

document.body.appendChild(div);
}, 1000);
}

// TODO execute `addCurrentTime` when the browser has completed loading the page
window.addEventListener('load', addCurrentTime);
39 changes: 37 additions & 2 deletions 2-Browsers/Week1/assignment/ex5-catWalk/index.js

Choose a reason for hiding this comment

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

Your solutions does seem to do something, but the cate moves at an incredibly slow pace, and it just seems like you might not have been crafting this solution yourself in a constructive way, and rather relying on prediction and/or AI.

I'd like to point out that for a development workflow, you need to at least follow these steps:

  1. Make sure you open the devtools console and take note of any errors that occur, so you get early feedback on possible problems in your code.
  2. Make small incremental steps towards a solution, while observing that your edits make actual changes in how your solution is working. It feels like you just put all the code in, without getting any feedback from your solution.
  3. Use tools like console.log(...) to figure out what's going on during the execution of your code, it you don't understand it. This can be extremely useful!

Please try to redo this exercise, following this process.

Note that this is the hardest exercise of the bunch, so it's totally understandable if you're having trouble with it :) I If you can't get any further with this exercise, it might be wise to schedule a little call (possibly shared with others) to discuss how to approach this kind of exercise. Let me know :)

Copy link
Author

Choose a reason for hiding this comment

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

I tried to do it, but I’m not sure. I think I have a problem with getting the middle of the screen and resuming the function. I would appreciate it if we could schedule a call to go through it thoroughly.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,43 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/2-B

https://media1.tenor.com/images/2de63e950fb254920054f9bd081e8157/tenor.gif
-----------------------------------------------------------------------------*/

const image = document.querySelector('img');
image.style.left = '0px';

const step = 10;
const danceUrl =
'https://media1.tenor.com/images/2de63e950fb254920054f9bd081e8157/tenor.gif';
const originalUrl = image.src;

let dancedThisLap = false;
let timer = setInterval(catWalk, 5000);

function catWalk() {
// TODO complete this function
const left = parseInt(image.style.left, 10);
const max = window.innerWidth - image.width;
const middle = Math.floor((window.innerWidth - image.width) / 2);

const newLeft = left + step;
image.style.left = newLeft + 'px';

if (newLeft >= max) {
image.style.left = '0px';
dancedThisLap = false;
return;
}

if (!dancedThisLap && newLeft >= middle) {
dancedThisLap = true;
clearInterval(timer);
image.src = danceUrl;

setTimeout(() => {
image.src = originalUrl;
image.style.left = middle + step + 'px';
timer = setInterval(catWalk, 5000);
}, 5000);
}
}

// TODO execute `catWalk` when the browser has completed loading the page
window.addEventListener('load', catWalk);
16 changes: 16 additions & 0 deletions 2-Browsers/Week1/assignment/extra.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function replaceLogo() {
const logo = document.querySelector(
'img[alt="Google"], img[src*="googlelogo"]'
);
if (!logo) return;
logo.src = chrome.runtime.getURL('images.png'); // uses packaged image
logo.removeAttribute('srcset');
logo.alt = 'HackYourFuture';
}

// run once
replaceLogo();

// reapply if the page updates the logo later
const obs = new MutationObserver(() => replaceLogo());
obs.observe(document.documentElement, { childList: true, subtree: true });
Binary file added 2-Browsers/Week1/assignment/images.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions 2-Browsers/Week1/assignment/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script src="extra.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions 2-Browsers/Week1/test-reports/ex1-bookList.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*** Unit Test Error Report ***

PASS .dist/2-Browsers/Week1/unit-tests/ex1-bookList.test.js
br-wk1-ex1-bookList
✅ HTML should be syntactically valid (165 ms)
✅ should have all TODO comments removed (1 ms)
✅ should contain a <ul> that is a child of <div id="bookList"> (1 ms)
✅ should contain a <ul> with 3 <li> elements (1 ms)
✅ should contain an <li> with title and author for each book of the `myBooks` array (2 ms)
✅ should contain an <img> element for each book (1 ms)

Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: 3.105 s, estimated 4 s
Ran all test suites matching /\/Users\/Alaa\/Desktop\/JavaScript-Cohort54\/.dist\/2-Browsers\/Week1\/unit-tests\/ex1-bookList.test.js/i.
No linting errors detected.


*** Spell Checker Report ***

2-Browsers/Week1/assignment/ex1-bookList/index.js:33:35 - Unknown word (lightgreen)
2-Browsers/Week1/assignment/ex1-bookList/index.js:35:35 - Unknown word (lightcoral)
21 changes: 21 additions & 0 deletions 2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*** Unit Test Error Report ***

PASS .dist/2-Browsers/Week1/unit-tests/ex2-aboutMe.test.js
br-wk1-ex2-aboutMe
✅ should be syntactically valid (316 ms)
✅ should have all TODO comments removed (1 ms)
✅ each <li> should have the CSS class `list-item` (1 ms)
✅ each <li> should rendered red (= rgb(255, 0, 0)) (24 ms)

Test Suites: 1 passed, 1 total
Tests: 4 passed, 4 total
Snapshots: 0 total
Time: 3.301 s
Ran all test suites matching /\/Users\/Alaa\/Desktop\/JavaScript-Cohort54\/.dist\/2-Browsers\/Week1\/unit-tests\/ex2-aboutMe.test.js/i.
No linting errors detected.


*** Spell Checker Report ***

2-Browsers/Week1/assignment/ex2-aboutMe/index.js:12:22 - Unknown word (Alooy)
2-Browsers/Week1/assignment/ex2-aboutMe/index.js:14:22 - Unknown word (Dongen)
19 changes: 19 additions & 0 deletions 2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*** Unit Test Error Report ***

PASS .dist/2-Browsers/Week1/unit-tests/ex3-hijackLogo.test.js
br-wk1-ex3-hijackLogo
✅ should have all TODO comments removed (1 ms)
✅ should set the `.src` property
✅ should set the `.srcset` property

Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 0.438 s, estimated 1 s
Ran all test suites matching /\/Users\/Alaa\/Desktop\/JavaScript-Cohort54\/.dist\/2-Browsers\/Week1\/unit-tests\/ex3-hijackLogo.test.js/i.
No linting errors detected.


*** Spell Checker Report ***

2-Browsers/Week1/assignment/ex3-hijackLogo.js:11:35 - Unknown word (googlelogo)
18 changes: 18 additions & 0 deletions 2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*** Unit Test Error Report ***

PASS .dist/2-Browsers/Week1/unit-tests/ex4-whatsTheTime.test.js
br-wk1-ex4-whatsTheTime
✅ HTML should be syntactically valid (171 ms)
✅ should have all TODO comments removed (1 ms)
✅ should use `setInterval()`
✅ should not call `setInterval()` more than once (2003 ms)
✅ should use `window.onload` or `window.addEventListener()` for the `load` or `DOMContentLoaded` event (1 ms)
✅ `window.onload` or `window.addEventListener` should not call its event handler function (1 ms)

Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: 4.988 s, estimated 5 s
Ran all test suites matching /\/Users\/Alaa\/Desktop\/JavaScript-Cohort54\/.dist\/2-Browsers\/Week1\/unit-tests\/ex4-whatsTheTime.test.js/i.
No linting errors detected.
No spelling errors detected.
17 changes: 17 additions & 0 deletions 2-Browsers/Week1/test-reports/ex5-catWalk.report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*** Unit Test Error Report ***

PASS .dist/2-Browsers/Week1/unit-tests/ex5-catWalk.test.js
br-wk1-ex5-catWalk
✅ HTML should be syntactically valid (165 ms)
✅ should have all TODO comments removed
✅ should use `setInterval()` and/or `setTimeout()`
✅ should use `window.onload` or `window.addEventListener()` for the `load` or `DOMContentLoaded` event
✅ `window.onload` or `window.addEventListener` should not call its event handler function (1 ms)

Test Suites: 1 passed, 1 total
Tests: 5 passed, 5 total
Snapshots: 0 total
Time: 2.958 s, estimated 3 s
Ran all test suites matching /\/Users\/Alaa\/Desktop\/JavaScript-Cohort54\/.dist\/2-Browsers\/Week1\/unit-tests\/ex5-catWalk.test.js/i.
No linting errors detected.
No spelling errors detected.