From 19df6bf2b48bc6eeaa6730a0747fb30fb94f813f Mon Sep 17 00:00:00 2001 From: Alaa Date: Wed, 17 Sep 2025 18:35:09 +0200 Subject: [PATCH 1/4] Alaa_Nasher-w1-browsers --- .test-summary/TEST_SUMMARY.md | 13 ++++++ .../Week1/assignment/ex1-bookList/index.js | 23 ++++++++++- .../Week1/assignment/ex1-bookList/style.css | 16 +++++++ .../Week1/assignment/ex2-aboutMe/index.js | 8 +++- .../Week1/assignment/ex2-aboutMe/style.css | 3 ++ 2-Browsers/Week1/assignment/ex3-hijackLogo.js | 8 +++- .../assignment/ex4-whatsTheTime/index.js | 15 ++++++- .../Week1/assignment/ex5-catWalk/index.js | 39 +++++++++++++++++- 2-Browsers/Week1/assignment/extra.js | 16 +++++++ 2-Browsers/Week1/assignment/images.png | Bin 0 -> 3822 bytes 2-Browsers/Week1/assignment/index.html | 11 +++++ .../test-reports/ex1-bookList.report.txt | 23 +++++++++++ .../Week1/test-reports/ex2-aboutMe.report.txt | 21 ++++++++++ .../test-reports/ex3-hijackLogo.report.txt | 19 +++++++++ .../test-reports/ex4-whatsTheTime.report.txt | 18 ++++++++ .../Week1/test-reports/ex5-catWalk.report.txt | 17 ++++++++ 16 files changed, 243 insertions(+), 7 deletions(-) create mode 100644 .test-summary/TEST_SUMMARY.md create mode 100644 2-Browsers/Week1/assignment/extra.js create mode 100644 2-Browsers/Week1/assignment/images.png create mode 100644 2-Browsers/Week1/assignment/index.html create mode 100644 2-Browsers/Week1/test-reports/ex1-bookList.report.txt create mode 100644 2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt create mode 100644 2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt create mode 100644 2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt create mode 100644 2-Browsers/Week1/test-reports/ex5-catWalk.report.txt diff --git a/.test-summary/TEST_SUMMARY.md b/.test-summary/TEST_SUMMARY.md new file mode 100644 index 000000000..7bd537db6 --- /dev/null +++ b/.test-summary/TEST_SUMMARY.md @@ -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 | - | ✓ | diff --git a/2-Browsers/Week1/assignment/ex1-bookList/index.js b/2-Browsers/Week1/assignment/ex1-bookList/index.js index 24a92487d..10139b943 100644 --- a/2-Browsers/Week1/assignment/ex1-bookList/index.js +++ b/2-Browsers/Week1/assignment/ex1-bookList/index.js @@ -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() { diff --git a/2-Browsers/Week1/assignment/ex1-bookList/style.css b/2-Browsers/Week1/assignment/ex1-bookList/style.css index 55ad76b29..67829aaee 100644 --- a/2-Browsers/Week1/assignment/ex1-bookList/style.css +++ b/2-Browsers/Week1/assignment/ex1-bookList/style.css @@ -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; +} diff --git a/2-Browsers/Week1/assignment/ex2-aboutMe/index.js b/2-Browsers/Week1/assignment/ex2-aboutMe/index.js index a03686b70..079c2613f 100644 --- a/2-Browsers/Week1/assignment/ex2-aboutMe/index.js +++ b/2-Browsers/Week1/assignment/ex2-aboutMe/index.js @@ -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'; +ul[1].textContent = 'Burgers'; +ul[2].textContent = 'Dongen'; + +const arr = Array.from(ul); +arr.forEach((ele) => (ele.className = 'list-item')); diff --git a/2-Browsers/Week1/assignment/ex2-aboutMe/style.css b/2-Browsers/Week1/assignment/ex2-aboutMe/style.css index 4e9cc415c..02518fbca 100644 --- a/2-Browsers/Week1/assignment/ex2-aboutMe/style.css +++ b/2-Browsers/Week1/assignment/ex2-aboutMe/style.css @@ -1 +1,4 @@ /* 3. Add a css rule for .list-item to make the color red. */ +.list-item { + color: red; +} diff --git a/2-Browsers/Week1/assignment/ex3-hijackLogo.js b/2-Browsers/Week1/assignment/ex3-hijackLogo.js index 1b3d596e9..3525e599a 100644 --- a/2-Browsers/Week1/assignment/ex3-hijackLogo.js +++ b/2-Browsers/Week1/assignment/ex3-hijackLogo.js @@ -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(); diff --git a/2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js b/2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js index 30dbdd61d..8f4df3fd5 100644 --- a/2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js +++ b/2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js @@ -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); + document.body.appendChild(div); + }, 1000); } -// TODO execute `addCurrentTime` when the browser has completed loading the page +window.addEventListener('load', addCurrentTime); diff --git a/2-Browsers/Week1/assignment/ex5-catWalk/index.js b/2-Browsers/Week1/assignment/ex5-catWalk/index.js index aedb02011..09f41dab9 100644 --- a/2-Browsers/Week1/assignment/ex5-catWalk/index.js +++ b/2-Browsers/Week1/assignment/ex5-catWalk/index.js @@ -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); diff --git a/2-Browsers/Week1/assignment/extra.js b/2-Browsers/Week1/assignment/extra.js new file mode 100644 index 000000000..db684c4c0 --- /dev/null +++ b/2-Browsers/Week1/assignment/extra.js @@ -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 }); diff --git a/2-Browsers/Week1/assignment/images.png b/2-Browsers/Week1/assignment/images.png new file mode 100644 index 0000000000000000000000000000000000000000..405542483d6e359b738ba3a888d445251d151298 GIT binary patch literal 3822 zcmV!vDbG|KI2T=A!?fv;VKD|EGZed_ey>&i~Af|B6iiMxFnfTmM-1|MqqNak>At z*#Fmi|97wdtdakYy8pPq|Gl;UvV{MEG5;uG|65M~Nyh)g9}3w^000gdNkl ziFTqe6ow^gYsF%5>nPT$ZPlvP_kX(~_XY^r1O%5h|2cC;2n|WTklgIGnw6E6m6erM zVfmr19R{mB8m-pzy5o?2x3_IxJ21aRM?&?kc5H&T!b-jCiLe9poDy}gg!eVRX2~EaSWmTK zD?yDgK^^j-c5H&w&Wv zy1A6RvghqO&11^E8fpOH9mm(t>G*LGCElvKdZ8$`2@5V!eG5!0M-?aHHMnPt*q*>q zg{?LMuSuXunI-&XUHsD@F+i1J19G!ZjW1`bAhxy_Vbi2|t+rT3Us{~Cqf4$#EQ+o6 zj@;D6tdcQo3IiHo0z#a;PTo=c*vKIgJ`5oI2fDlG6;gO+wyyX7NeBgMxKiEvj9~kHTq; zPICDz*KKkkTL7E)?>nWB@lO=duEw7;RSerF1nLt4rZ!66Fy$P0!z#W8Z_eH7PIu`uOyG57Hs z!3znSKMXYjTaau|g?@-$_4vSHmPzbee?&ce1rNVP5AgLL^pPP;`|_}19a~A0y9hS= z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9STxh3}(##URrD9-(%5QT9~6E-}rm#+yeHc7r$Vj&so zF^~>-BBU!GL2JUs4j$uH_5ZCxlIk?JWmlya-5=udQieSW7K3?uwt@E|KW#iwDga0B z#L12_h}|FExl8w~MW-_yc1k~DtR4C~?3j<`93I!*1I$C6&DSl}Vb3G*#rTTOZ#3_3 kUyF9LS;e_@R#vy9{|)C0r`Wad{{R3007*qoM6N<$f|uiXtpET3 literal 0 HcmV?d00001 diff --git a/2-Browsers/Week1/assignment/index.html b/2-Browsers/Week1/assignment/index.html new file mode 100644 index 000000000..264156e7f --- /dev/null +++ b/2-Browsers/Week1/assignment/index.html @@ -0,0 +1,11 @@ + + + + + + Document + + + + + diff --git a/2-Browsers/Week1/test-reports/ex1-bookList.report.txt b/2-Browsers/Week1/test-reports/ex1-bookList.report.txt new file mode 100644 index 000000000..3253bb575 --- /dev/null +++ b/2-Browsers/Week1/test-reports/ex1-bookList.report.txt @@ -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
    that is a child of
    (1 ms) + ✅ should contain a
      with 3
    • elements (1 ms) + ✅ should contain an
    • with title and author for each book of the `myBooks` array (2 ms) + ✅ should contain an 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) diff --git a/2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt b/2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt new file mode 100644 index 000000000..e523b9d0d --- /dev/null +++ b/2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt @@ -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
    • should have the CSS class `list-item` (1 ms) + ✅ each
    • 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) diff --git a/2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt b/2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt new file mode 100644 index 000000000..6e19271bb --- /dev/null +++ b/2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt @@ -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) diff --git a/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt b/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt new file mode 100644 index 000000000..4755fd943 --- /dev/null +++ b/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt @@ -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 (162 ms) + ✅ should have all TODO comments removed + ✅ should use `setInterval()` (1 ms) + ✅ should not call `setInterval()` more than once (2002 ms) + ✅ 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 + +Test Suites: 1 passed, 1 total +Tests: 6 passed, 6 total +Snapshots: 0 total +Time: 4.951 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. diff --git a/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt b/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt new file mode 100644 index 000000000..68fd069f0 --- /dev/null +++ b/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt @@ -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 (161 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: 3.087 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. From 4f945a683ccfbf8ebbc69625231713a4180bc4c1 Mon Sep 17 00:00:00 2001 From: Alaa Date: Wed, 17 Sep 2025 18:41:07 +0200 Subject: [PATCH 2/4] Alaa_Nasher-w1-Browsers-add tests --- .../Week1/test-reports/ex4-whatsTheTime.report.txt | 14 +++++++------- .../Week1/test-reports/ex5-catWalk.report.txt | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt b/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt index 4755fd943..50dd090a0 100644 --- a/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt +++ b/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt @@ -2,17 +2,17 @@ PASS .dist/2-Browsers/Week1/unit-tests/ex4-whatsTheTime.test.js br-wk1-ex4-whatsTheTime - ✅ HTML should be syntactically valid (162 ms) - ✅ should have all TODO comments removed - ✅ should use `setInterval()` (1 ms) - ✅ should not call `setInterval()` more than once (2002 ms) - ✅ 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 + ✅ 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.951 s, estimated 5 s +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. diff --git a/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt b/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt index 68fd069f0..ef88d43a6 100644 --- a/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt +++ b/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt @@ -2,7 +2,7 @@ PASS .dist/2-Browsers/Week1/unit-tests/ex5-catWalk.test.js br-wk1-ex5-catWalk - ✅ HTML should be syntactically valid (161 ms) + ✅ 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 @@ -11,7 +11,7 @@ Test Suites: 1 passed, 1 total Tests: 5 passed, 5 total Snapshots: 0 total -Time: 3.087 s +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. From 4fd2e1d8af22e09c8d1b0dfd37740cffd6ed6733 Mon Sep 17 00:00:00 2001 From: Alaa Date: Sat, 20 Sep 2025 21:33:48 +0200 Subject: [PATCH 3/4] Fix code week-1 Browsers --- .../Week1/assignment/ex2-aboutMe/index.js | 10 ++-- 2-Browsers/Week1/assignment/ex3-hijackLogo.js | 15 +++--- .../assignment/ex4-whatsTheTime/index.js | 8 +-- .../Week1/assignment/ex5-catWalk/index.js | 49 +++++++----------- 2-Browsers/Week1/assignment/extra.js | 16 ------ 2-Browsers/Week1/assignment/images.png | Bin 3822 -> 0 bytes 2-Browsers/Week1/assignment/index.html | 11 ---- .../test-reports/ex1-bookList.report.txt | 8 +-- .../Week1/test-reports/ex2-aboutMe.report.txt | 14 ++--- .../test-reports/ex3-hijackLogo.report.txt | 6 +-- .../test-reports/ex4-whatsTheTime.report.txt | 12 ++--- .../Week1/test-reports/ex5-catWalk.report.txt | 10 ++-- 12 files changed, 64 insertions(+), 95 deletions(-) delete mode 100644 2-Browsers/Week1/assignment/extra.js delete mode 100644 2-Browsers/Week1/assignment/images.png delete mode 100644 2-Browsers/Week1/assignment/index.html diff --git a/2-Browsers/Week1/assignment/ex2-aboutMe/index.js b/2-Browsers/Week1/assignment/ex2-aboutMe/index.js index 079c2613f..d1b8fa06b 100644 --- a/2-Browsers/Week1/assignment/ex2-aboutMe/index.js +++ b/2-Browsers/Week1/assignment/ex2-aboutMe/index.js @@ -9,9 +9,13 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/2-B ------------------------------------------------------------------------------*/ const ul = document.querySelector('ul').children; -ul[0].textContent = 'Alooy'; -ul[1].textContent = 'Burgers'; -ul[2].textContent = 'Dongen'; +const nickname = document.getElementById('nickname'); +const favFood = document.getElementById('fav-food'); +const hometown = document.getElementById('hometown'); + +nickname.textContent = 'Alooy'; +favFood.textContent = 'Burgers'; +hometown.textContent = 'Dongen'; const arr = Array.from(ul); arr.forEach((ele) => (ele.className = 'list-item')); diff --git a/2-Browsers/Week1/assignment/ex3-hijackLogo.js b/2-Browsers/Week1/assignment/ex3-hijackLogo.js index 3525e599a..3d7795f63 100644 --- a/2-Browsers/Week1/assignment/ex3-hijackLogo.js +++ b/2-Browsers/Week1/assignment/ex3-hijackLogo.js @@ -7,13 +7,12 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/2-B HackYourFuture logo instead. ------------------------------------------------------------------------------*/ function hijackGoogleLogo() { - const logo = document.querySelector( - 'img[alt="Google"], img[src*="googlelogo"]' - ); - - logo.src = 'images.png'; - logo.srcset = 'images.png'; - logo.alt = 'HackYourFuture'; + const logo = document.querySelector('svg.lnXdpd'); + const hyfLogo = + 'https://github.com/HackYourFuture/Assignments/raw/main/assets/hyf-logo-black-bg-small.png'; + const img = document.createElement('img'); + img.src = hyfLogo; + img.srcset = hyfLogo; + logo.replaceWith(img); } - hijackGoogleLogo(); diff --git a/2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js b/2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js index 8f4df3fd5..d2562b548 100644 --- a/2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js +++ b/2-Browsers/Week1/assignment/ex4-whatsTheTime/index.js @@ -6,19 +6,21 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/2-B second). Use `setInterval()` to make sure the time stays current. 2. Have the function execute when it's loading in the browser. ------------------------------------------------------------------------------*/ + function addCurrentTime() { const div = document.createElement('div'); const span = document.createElement('span'); - return setInterval(function () { + 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); - document.body.appendChild(div); }, 1000); + + div.appendChild(span); + document.body.appendChild(div); } window.addEventListener('load', addCurrentTime); diff --git a/2-Browsers/Week1/assignment/ex5-catWalk/index.js b/2-Browsers/Week1/assignment/ex5-catWalk/index.js index 09f41dab9..fbeb9cbec 100644 --- a/2-Browsers/Week1/assignment/ex5-catWalk/index.js +++ b/2-Browsers/Week1/assignment/ex5-catWalk/index.js @@ -20,43 +20,34 @@ 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); +// console.log(originalUrl); function catWalk() { - 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'; + intervalId = setInterval(function () { + const stepToLeft = parseInt(image.style.left, 10) + 10; + image.style.left = `${stepToLeft}px`; - if (newLeft >= max) { - image.style.left = '0px'; - dancedThisLap = false; - return; - } + // check if it reaches the end of the screen + if (stepToLeft > window.outerWidth - image.width) image.style.left = '0px'; - if (!dancedThisLap && newLeft >= middle) { - dancedThisLap = true; - clearInterval(timer); - image.src = danceUrl; - - setTimeout(() => { + // check if it reaches the middle of the screen + if (stepToLeft > window.outerWidth - image.width / 2) { + // middle(); + stopDancing(); image.src = originalUrl; - image.style.left = middle + step + 'px'; - timer = setInterval(catWalk, 5000); - }, 5000); - } + } + }, 50); +} + +function stopDancing() { + setTimeout(function () { + clearInterval(intervalId); + image.src = + 'https://media1.tenor.com/images/2de63e950fb254920054f9bd081e8157/tenor.gif'; + }, 5000); } window.addEventListener('load', catWalk); diff --git a/2-Browsers/Week1/assignment/extra.js b/2-Browsers/Week1/assignment/extra.js deleted file mode 100644 index db684c4c0..000000000 --- a/2-Browsers/Week1/assignment/extra.js +++ /dev/null @@ -1,16 +0,0 @@ -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 }); diff --git a/2-Browsers/Week1/assignment/images.png b/2-Browsers/Week1/assignment/images.png deleted file mode 100644 index 405542483d6e359b738ba3a888d445251d151298..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3822 zcmV!vDbG|KI2T=A!?fv;VKD|EGZed_ey>&i~Af|B6iiMxFnfTmM-1|MqqNak>At z*#Fmi|97wdtdakYy8pPq|Gl;UvV{MEG5;uG|65M~Nyh)g9}3w^000gdNkl ziFTqe6ow^gYsF%5>nPT$ZPlvP_kX(~_XY^r1O%5h|2cC;2n|WTklgIGnw6E6m6erM zVfmr19R{mB8m-pzy5o?2x3_IxJ21aRM?&?kc5H&T!b-jCiLe9poDy}gg!eVRX2~EaSWmTK zD?yDgK^^j-c5H&w&Wv zy1A6RvghqO&11^E8fpOH9mm(t>G*LGCElvKdZ8$`2@5V!eG5!0M-?aHHMnPt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S+SN#cxH2=00O0W#QRQZ_Nh%i`p4~Q6Z@-C-^Z43;4PP8}I$CU! z%Ei{izI*klW&`0JhCcjB%hkz8Xsw4u}LZ!8_sW3o;TFN z)>zW9Z<>?UB0q{biXXTpZ2 z4Z8?v5T8fNFphpB&C}T0(1QyJBWnk)vN>)Zg7GMSXYevAevDX~Kplk1-G2 zFc9uQ9Yk@h@UPHmY^c3@fvv8)!-TCC5hCQ!e}7o5Uf0j@XiUn)G-2yXZ}@wQfKOuc zHRH#Hu(h4YGjXDUP~(}fO{9STxh3}(##URrD9-(%5QT9~6E-}rm#+yeHc7r$Vj&so zF^~>-BBU!GL2JUs4j$uH_5ZCxlIk?JWmlya-5=udQieSW7K3?uwt@E|KW#iwDga0B z#L12_h}|FExl8w~MW-_yc1k~DtR4C~?3j<`93I!*1I$C6&DSl}Vb3G*#rTTOZ#3_3 kUyF9LS;e_@R#vy9{|)C0r`Wad{{R3007*qoM6N<$f|uiXtpET3 diff --git a/2-Browsers/Week1/assignment/index.html b/2-Browsers/Week1/assignment/index.html deleted file mode 100644 index 264156e7f..000000000 --- a/2-Browsers/Week1/assignment/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - Document - - - - - diff --git a/2-Browsers/Week1/test-reports/ex1-bookList.report.txt b/2-Browsers/Week1/test-reports/ex1-bookList.report.txt index 3253bb575..18773744f 100644 --- a/2-Browsers/Week1/test-reports/ex1-bookList.report.txt +++ b/2-Browsers/Week1/test-reports/ex1-bookList.report.txt @@ -2,17 +2,17 @@ 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) + ✅ HTML should be syntactically valid (168 ms) + ✅ should have all TODO comments removed ✅ should contain a
        that is a child of
        (1 ms) ✅ should contain a
          with 3
        • elements (1 ms) - ✅ should contain an
        • with title and author for each book of the `myBooks` array (2 ms) + ✅ should contain an
        • with title and author for each book of the `myBooks` array (1 ms) ✅ should contain an 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 +Time: 3.056 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. diff --git a/2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt b/2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt index e523b9d0d..8664c6ef7 100644 --- a/2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt +++ b/2-Browsers/Week1/test-reports/ex2-aboutMe.report.txt @@ -2,20 +2,20 @@ 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
        • should have the CSS class `list-item` (1 ms) - ✅ each
        • should rendered red (= rgb(255, 0, 0)) (24 ms) + ✅ should be syntactically valid (167 ms) + ✅ should have all TODO comments removed + ✅ each
        • should have the CSS class `list-item` (2 ms) + ✅ each
        • should rendered red (= rgb(255, 0, 0)) (23 ms) Test Suites: 1 passed, 1 total Tests: 4 passed, 4 total Snapshots: 0 total -Time: 3.301 s +Time: 3.083 s, estimated 5 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) +2-Browsers/Week1/assignment/ex2-aboutMe/index.js:16:25 - Unknown word (Alooy) +2-Browsers/Week1/assignment/ex2-aboutMe/index.js:18:25 - Unknown word (Dongen) diff --git a/2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt b/2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt index 6e19271bb..30c213abd 100644 --- a/2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt +++ b/2-Browsers/Week1/test-reports/ex3-hijackLogo.report.txt @@ -2,18 +2,18 @@ PASS .dist/2-Browsers/Week1/unit-tests/ex3-hijackLogo.test.js br-wk1-ex3-hijackLogo - ✅ should have all TODO comments removed (1 ms) + ✅ should have all TODO comments removed (2 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 +Time: 0.477 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) +2-Browsers/Week1/assignment/ex3-hijackLogo.js:10:46 - Unknown word (Xdpd) diff --git a/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt b/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt index 50dd090a0..818297d12 100644 --- a/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt +++ b/2-Browsers/Week1/test-reports/ex4-whatsTheTime.report.txt @@ -2,17 +2,17 @@ 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) + ✅ HTML should be syntactically valid (165 ms) + ✅ should have all TODO comments removed + ✅ should use `setInterval()` (1 ms) + ✅ should not call `setInterval()` more than once (2002 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) + ✅ `window.onload` or `window.addEventListener` should not call its event handler function Test Suites: 1 passed, 1 total Tests: 6 passed, 6 total Snapshots: 0 total -Time: 4.988 s, estimated 5 s +Time: 5.055 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. diff --git a/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt b/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt index ef88d43a6..52fb006a0 100644 --- a/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt +++ b/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt @@ -2,16 +2,16 @@ 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 + ✅ HTML should be syntactically valid (167 ms) + ✅ should have all TODO comments removed (1 ms) ✅ 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) + ✅ 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 Test Suites: 1 passed, 1 total Tests: 5 passed, 5 total Snapshots: 0 total -Time: 2.958 s, estimated 3 s +Time: 3.051 s, estimated 4 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. From 4b1b83609108c920cf76749a275282de9386f13c Mon Sep 17 00:00:00 2001 From: Alaa Date: Thu, 16 Oct 2025 23:15:35 +0200 Subject: [PATCH 4/4] Fix errors in catWalk.js --- .vscode/settings.json | 3 +- .../Week1/assignment/ex5-catWalk/index.js | 29 +++++++++++-------- .../Week1/test-reports/ex5-catWalk.report.txt | 10 +++---- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f7d6e29e1..a455d2bb5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,5 +16,6 @@ "editor.bracketPairColorization.enabled": true, "editor.guides.bracketPairs": true, "editor.guides.highlightActiveIndentation": true, - "editor.guides.bracketPairsHorizontal": "active" + "editor.guides.bracketPairsHorizontal": "active", + "liveServer.settings.port": 5501 } diff --git a/2-Browsers/Week1/assignment/ex5-catWalk/index.js b/2-Browsers/Week1/assignment/ex5-catWalk/index.js index fbeb9cbec..9129b9b9f 100644 --- a/2-Browsers/Week1/assignment/ex5-catWalk/index.js +++ b/2-Browsers/Week1/assignment/ex5-catWalk/index.js @@ -23,31 +23,36 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/2-B const image = document.querySelector('img'); image.style.left = '0px'; const originalUrl = image.src; -// console.log(originalUrl); +let dancing = false; + +const screenWidth = window.innerWidth - image.width; +const middle = screenWidth / 2; function catWalk() { - intervalId = setInterval(function () { + setInterval(function () { + if (dancing) return; + const stepToLeft = parseInt(image.style.left, 10) + 10; image.style.left = `${stepToLeft}px`; - // check if it reaches the end of the screen - if (stepToLeft > window.outerWidth - image.width) image.style.left = '0px'; + if (stepToLeft >= screenWidth) { + image.style.left = '0px'; + return; + } - // check if it reaches the middle of the screen - if (stepToLeft > window.outerWidth - image.width / 2) { - // middle(); + if (stepToLeft >= middle && stepToLeft < middle + 10) { stopDancing(); - image.src = originalUrl; } }, 50); } function stopDancing() { + dancing = true; + image.src = + 'https://media1.tenor.com/images/2de63e950fb254920054f9bd081e8157/tenor.gif'; setTimeout(function () { - clearInterval(intervalId); - image.src = - 'https://media1.tenor.com/images/2de63e950fb254920054f9bd081e8157/tenor.gif'; + image.src = originalUrl; + dancing = false; }, 5000); } - window.addEventListener('load', catWalk); diff --git a/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt b/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt index 52fb006a0..420d3c7e8 100644 --- a/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt +++ b/2-Browsers/Week1/test-reports/ex5-catWalk.report.txt @@ -1,17 +1,17 @@ *** Unit Test Error Report *** - PASS .dist/2-Browsers/Week1/unit-tests/ex5-catWalk.test.js + PASS .dist/2-Browsers/Week1/unit-tests/ex5-catWalk.test.js (14.285 s) br-wk1-ex5-catWalk - ✅ HTML should be syntactically valid (167 ms) + ✅ HTML should be syntactically valid (193 ms) ✅ should have all TODO comments removed (1 ms) ✅ should use `setInterval()` and/or `setTimeout()` - ✅ 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 + ✅ 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: 3.051 s, estimated 4 s +Time: 15.384 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.