From 6a4ffd33c2b476d7984ab1a21928ac910f58046a Mon Sep 17 00:00:00 2001 From: Jalal Al Attar Date: Sun, 26 Jan 2020 00:00:30 +0100 Subject: [PATCH 1/3] all exercises for J3 W1 and the broject is not complete yet .. I will complete it on Monday --- Week1/HomeWork/js-exercises/ex-1.html | 14 +++++++ Week1/HomeWork/js-exercises/ex-1.js | 42 ++++++++++++++++++++ Week1/HomeWork/js-exercises/ex-2.html | 14 +++++++ Week1/HomeWork/js-exercises/ex-2.js | 47 +++++++++++++++++++++++ Week1/HomeWork/js-exercises/ex-3.html | 18 +++++++++ Week1/HomeWork/js-exercises/ex-3.js | 55 +++++++++++++++++++++++++++ 6 files changed, 190 insertions(+) create mode 100644 Week1/HomeWork/js-exercises/ex-1.html create mode 100644 Week1/HomeWork/js-exercises/ex-1.js create mode 100644 Week1/HomeWork/js-exercises/ex-2.html create mode 100644 Week1/HomeWork/js-exercises/ex-2.js create mode 100644 Week1/HomeWork/js-exercises/ex-3.html create mode 100644 Week1/HomeWork/js-exercises/ex-3.js diff --git a/Week1/HomeWork/js-exercises/ex-1.html b/Week1/HomeWork/js-exercises/ex-1.html new file mode 100644 index 000000000..e8ed8671d --- /dev/null +++ b/Week1/HomeWork/js-exercises/ex-1.html @@ -0,0 +1,14 @@ + + + + + + Make a new friend + + + + + + + + \ No newline at end of file diff --git a/Week1/HomeWork/js-exercises/ex-1.js b/Week1/HomeWork/js-exercises/ex-1.js new file mode 100644 index 000000000..a54721c5a --- /dev/null +++ b/Week1/HomeWork/js-exercises/ex-1.js @@ -0,0 +1,42 @@ +'use strict'; + +// inside the same file write two functions: +// one with XMLHttpRequest() + +const button = document.querySelector('#btn'); + +const serverRequest = () => { + const xhr = new XMLHttpRequest(); + + xhr.responseType = 'json'; + + xhr.onreadystatechange = () => { + if (xhr.readyState === XMLHttpRequest.DONE) { + console.log(xhr.response); + } else { + console.error(); + } + }; + xhr.open('GET', 'https://www.randomuser.me/api'); + xhr.send(); +}; + +button.addEventListener('click', serverRequest); + +// and the other with : +// axios + +const axiosRequest = () => { + + axios.get('https://www.randomuser.me/api') + + .then(function(response) { + console.log('this apparently was seccesfull',response.data); + }) + .catch(function(error) { + console.log('there are some errors',error); + }) + .finally(function(){ + console.log('let me know what happend') + }) +}; \ No newline at end of file diff --git a/Week1/HomeWork/js-exercises/ex-2.html b/Week1/HomeWork/js-exercises/ex-2.html new file mode 100644 index 000000000..25a9c827a --- /dev/null +++ b/Week1/HomeWork/js-exercises/ex-2.html @@ -0,0 +1,14 @@ + + + + + + Programmer humor + + + + + + + + \ No newline at end of file diff --git a/Week1/HomeWork/js-exercises/ex-2.js b/Week1/HomeWork/js-exercises/ex-2.js new file mode 100644 index 000000000..89bf3c8a4 --- /dev/null +++ b/Week1/HomeWork/js-exercises/ex-2.js @@ -0,0 +1,47 @@ +'use strict'; + +// one with XMLHttpRequest + +const humorRequest = () => { + const xhr = new XMLHttpRequest(); + + const img = document.querySelector('#img'); + + xhr.responseType = 'json'; + + xhr.onreadystatechange = () => { + if (xhr.readyState === XMLHttpRequest.DONE) { + console.log(xhr.response); + img.setAttribute('src', xhr.response.img); + } else { + console.error(); + } + }; + xhr.open('GET', 'https://xkcd.now.sh/?comic=614 '); + xhr.send(); + }; + + humorRequest(); + +// and the other with : +// axios + + const requestHumor = () => { + + const img = document.querySelector('#img'); + + axios + .get('https://xkcd.now.sh/?comic=614') + + .then(function(response) { + console.log('this apparently was seccesfull',response); + img.setAttribute('src', response.data.img); + }) + .catch(function(error) { + console.log('there are some errors', error); + }) + .finally(function(){ + console.log('let me know what happend') + }) + }; + requestHumor(); \ No newline at end of file diff --git a/Week1/HomeWork/js-exercises/ex-3.html b/Week1/HomeWork/js-exercises/ex-3.html new file mode 100644 index 000000000..fbeff0300 --- /dev/null +++ b/Week1/HomeWork/js-exercises/ex-3.html @@ -0,0 +1,18 @@ + + + + + + Dog photo gallery + + + + + + + + + + + + \ No newline at end of file diff --git a/Week1/HomeWork/js-exercises/ex-3.js b/Week1/HomeWork/js-exercises/ex-3.js new file mode 100644 index 000000000..92311e3d8 --- /dev/null +++ b/Week1/HomeWork/js-exercises/ex-3.js @@ -0,0 +1,55 @@ + +'use strict'; + +// one with XMLHttpRequest() + +const btnNormal = document.querySelector('#normal'); + +const randomDogNormal = () => { + const xhr = new XMLHttpRequest(); + const ul = document.querySelector('#ulList'); + + xhr.responseType = 'json'; + + xhr.onreadystatechange = () => { + if (xhr.readyState === XMLHttpRequest.DONE) { + const li = document.createElement('li'); + const img = document.createElement('img'); + img.setAttribute('src', xhr.response.message); + li.appendChild(img); + ul.appendChild(li); + } else { + console.log(`${xhr.status}`); + } + }; + + xhr.open('GET', 'https://dog.ceo/api/breeds/image/random'); + xhr.send(); +}; +btnNormal.addEventListener('click', randomDogNormal); + +// and the other with : +// axios + +const btnAxios = document.querySelector('#axios'); + +const randomDogAxios = () => { + const ul = document.querySelector('#ulList'); + + axios.get('https://dog.ceo/api/breeds/image/random') + + .then(function(response) { + const li = document.createElement('li'); + const img = document.createElement('img'); + img.setAttribute('src', response.data.message); + li.appendChild(img); + ul.appendChild(li); + }) + .catch(function(error) { + console.log('there are some errors', error); + }) + .finally(function(){ + console.log('let me know what happend') + }) +}; +btnAxios.addEventListener('click', randomDogAxios); \ No newline at end of file From 1dcd8174f2bb9a121e70d466ad56ba5fe0940104 Mon Sep 17 00:00:00 2001 From: Jalal Al Attar Date: Sun, 26 Jan 2020 12:24:18 +0100 Subject: [PATCH 2/3] changed name of js file --- Week1/HomeWork/js-exercises/ex-3.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week1/HomeWork/js-exercises/ex-3.html b/Week1/HomeWork/js-exercises/ex-3.html index fbeff0300..915473392 100644 --- a/Week1/HomeWork/js-exercises/ex-3.html +++ b/Week1/HomeWork/js-exercises/ex-3.html @@ -13,6 +13,6 @@ - + \ No newline at end of file From 82d767b0868d056b0be74ba32d5acbeb0a049e19 Mon Sep 17 00:00:00 2001 From: Jalal Al Attar Date: Sat, 1 Feb 2020 23:14:06 +0100 Subject: [PATCH 3/3] Project j3 w1 --- .../js-exercises/Project j3 w1/HYF.png | Bin 0 -> 6587 bytes .../js-exercises/Project j3 w1/index.html | 18 ++++ .../js-exercises/Project j3 w1/index.js | 81 ++++++++++++++++++ .../js-exercises/Project j3 w1/style.css | 57 ++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 Week1/HomeWork/js-exercises/Project j3 w1/HYF.png create mode 100644 Week1/HomeWork/js-exercises/Project j3 w1/index.html create mode 100644 Week1/HomeWork/js-exercises/Project j3 w1/index.js create mode 100644 Week1/HomeWork/js-exercises/Project j3 w1/style.css diff --git a/Week1/HomeWork/js-exercises/Project j3 w1/HYF.png b/Week1/HomeWork/js-exercises/Project j3 w1/HYF.png new file mode 100644 index 0000000000000000000000000000000000000000..bd27a0444adbe29e9ce557107950df4326994180 GIT binary patch literal 6587 zcmeHM=RX_X+tx*EeC^$!tyQT}dn>IOt2Mu7?GmG6mBcPeZCWH&jo7hAB&9_uwMT49 z2@-qPeDeDPp6A`~-Sgslan6hToXR8M6=vX`WZ#~J@!T-{fBbjPAirXRT=C!-@1)Uvwz;pl zDrFmbUT?K@N;dTOK!7f(-s^g`pn!52S$nnpkwyR2aP+T?G_S5=;FyK5aQ9@76Qm}i zIqBoak5#d;UmCC`Q>Lb-Ik`5e>DjET84LWWH7C~Xo`YfvK>t9H&#XY+r5S2Bpgn<2 zc`kY?8uU_I#>+);%wip^NIBZ2T{zI6FtvIo&}mamL7^hqkbBu%KezSAkuZKJ?^|O= zI%x@URZ6Non>xv^$;nS&d%qbjP7DlA40vv1^9kkA>+37eV;ndU@2!dPoNG&XyP<{V zFKy~5Ud8^CDAp3X+2pL33^7c5bNS8{?Ed+RQFYuhe8*OEGH}Nq3jsD&z#aC4?W$$j5`XgOl&H_047aIu?&=9t3Q~R`iiu=2L?PB+f-c3Mvcq#5T7%%==DdaJKYyU9x7<& zpFQ|eOnqn*T-$S%PP1E$73BH>aZ5H~6@6kIBh{ zAg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ODk)i!n0pl7$|tZ2ZoPN76n~rWD5W73eb9e|pp~4bJEJSIq4%!Lrf{$7Xd<~`4s%XwLNg~Qz?IHFx8+CAI7iynl ztbfw;MpVrvT4DTcv*3RNvwzjh&@`q4m*BPtJGSt!gHIq)?XH!_TY3ZW7clEq6sV%2 zaEnOPskAz3X)DH*+G5|H=-W3<3idet>YTFlh|Yut$^p4~vB>}{A+E_uV;MS`gnbBH zN1ueNy;=U{}eR6Qm|=x=Y@|CdwTW0myOgI5+F~AH(ORp z4G+%^Zs%xv55g?;^*`zD<2{r#dF9~n>xeV>T=sPTQ_;d^$l*^DlYnXTfv!k z+zB`jo%zukfFheP{#~y$NmzPqUsYZ*MZC~_>Ai~JY>Q3MHmM8I)B9tI2*|tCUZo8f z`p}g+6p(#2S#s^Mg=#J}hC+L2d#b(8cQf-VTU{2P3Yfj!c31RHBURhJPexFG^92qp zE$8isa>RWZfh1_ddoV>OY7Xc_-Hm!sz*hw%E?7=%8aEM z?Z<+JfTzW^wo#Yw2)N-dEM0v7Kzw9QV?Gv6d~^8^E_utc?t7K6+Di&>(2Inzv9Xb{ ziIkA}xem02gfDnEH)T9>El)p1>mkDz49}ew&71jTs{fDw<{A9HzC}iMeVr3I%i~)! SF;4oFA=6gZe}Pha9q~UktBz>^ literal 0 HcmV?d00001 diff --git a/Week1/HomeWork/js-exercises/Project j3 w1/index.html b/Week1/HomeWork/js-exercises/Project j3 w1/index.html new file mode 100644 index 000000000..a21588870 --- /dev/null +++ b/Week1/HomeWork/js-exercises/Project j3 w1/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + PROJECT: Hack Your Repo I j3 w1 + + +
+ + + \ No newline at end of file diff --git a/Week1/HomeWork/js-exercises/Project j3 w1/index.js b/Week1/HomeWork/js-exercises/Project j3 w1/index.js new file mode 100644 index 000000000..0961f42e9 --- /dev/null +++ b/Week1/HomeWork/js-exercises/Project j3 w1/index.js @@ -0,0 +1,81 @@ +'use strict'; +{ +// window.onload = () => main(HYF_REPOS_URL_ERROR); // to get ERROR +// const HYF_REPOS_URL_ERROR ='https://api.github.com/orgsX/HackYourFuture/repos?per_page=100'; + + window.onload = () => main(HYF_REPOS_URL); + const HYF_REPOS_URL ='https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; + const root = document.querySelector('#root'); + + function fetchJSON(url, callback) { + const xhr = new XMLHttpRequest(); + xhr.open('GET', url); + xhr.responseType = 'json'; + xhr.onload = () => { + if (xhr.status >= 200 && xhr.status < 300) { + callback(null, xhr.response); + } else { + callback(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`)); + } + }; + xhr.onerror = () => callback(new Error('Network request failed')); + xhr.send(); + } + + function main(url) { + createAndAppend('img', root, { src: 'HYF.png' }); + createAndAppend('h3', root, { text: 'HYF Repositories' }); + fetchJSON(url, (error, response) => { + if (error) { + createAndAppend('div', root, { + text: error.message, + class: 'alert-error', + }); + return; + } + const ul = createAndAppend('ul', root); + response.sort((curRepo, nextRepo) => curRepo.name.localeCompare(nextRepo.name)) + // Display the first 10 items + .slice(0, 10) + .forEach(repo => repoDetails(repo, ul)) + }); + } + + function repoDetails(repo, ul) { + const li = createAndAppend('li', ul); + const table = createAndAppend('table', li); + const titles = ['Repository:', 'Description:', 'Forks:', 'Updated:']; + const dataKeys = ['name', 'description', 'forks', 'updated_at']; + + for (let i = 0; i < titles.length; ++i) { + + const tr = createAndAppend('tr', table); + createAndAppend('th', tr, { text: titles[i] }); + if (i > 0 ){ + createAndAppend('td', tr, { text: repo[dataKeys[i]] }); + } else { + const td = createAndAppend('td', tr); + createAndAppend('a', td, { + href: repo.html_url, + text: repo.name, + target: '_blank', + }); + } + } + } + + + function createAndAppend(name, parent, options = {}) { + const el = document.createElement(name); + parent.appendChild(el); + Object.entries(options).forEach(([key, value]) => { + if (key === 'text') { + el.textContent = value; + } else { + el.setAttribute(key, value); + } + }); + return el; + }; + +}; \ No newline at end of file diff --git a/Week1/HomeWork/js-exercises/Project j3 w1/style.css b/Week1/HomeWork/js-exercises/Project j3 w1/style.css new file mode 100644 index 000000000..fb8b8baa8 --- /dev/null +++ b/Week1/HomeWork/js-exercises/Project j3 w1/style.css @@ -0,0 +1,57 @@ +*{ + padding: 0; + margin: 0; + box-sizing: border-box; + font-family: 'Roboto', sans-serif; +} +img{ + float: left; + width: 25px; + height: 25px; + border-radius: 0 50% 50% 50%; +} +body { + padding: 25px; +} +h3 { + font-weight: lighter; + background-color: #253dc5; + padding: 35px; + padding-left: 25px; + color: whitesmoke; + +} +table { + width: 100%; + margin-top: 3px; + padding: 20px; + border: 1px solid rgb(240, 240, 240) ; + border-radius: 4px; + box-shadow: 0px 3px 3px rgb(179, 178, 178) ; + color: #333; +} +th { + width: 10%; + padding: 3px; +} +li:nth-child(even) { + background: rgb(224, 224, 224); +} +li { + list-style: none; +} + +.alert-error { + margin-top: 2px; + padding: 20px; + padding-left: 25px; + border-radius: 6px; + color: brown; + background-color: #f0c6ca; +} +@media (max-width: 650px) { + table, header { + width: 100%; + margin: 0 auto; + } +} \ No newline at end of file