From bf60a0b61441aaf7ae1bc3916f84443c5ade9052 Mon Sep 17 00:00:00 2001 From: Tomer Sagi Date: Mon, 11 Dec 2023 11:33:09 +0200 Subject: [PATCH] Lesson 12 - Code and exercises --- {29.11.23 => 10 - 29.11.23}/async/index.html | 0 {29.11.23 => 10 - 29.11.23}/async/script.js | 0 .../async_clear_interval/index.html | 0 .../async_clear_interval/script.js | 0 .../async_exercise/index.html | 0 .../async_exercise/script.js | 0 .../xmlhttprequest/index.html | 0 .../xmlhttprequest/script.js | 0 .../xmlhttprequest/index.html | 0 .../xmlhttprequest/script.js | 0 .../xmlhttprequest_exercise/index.html | 0 .../xmlhttprequest_exercise/script.js | 0 .../xmlhttprequest_post/index.html | 0 .../xmlhttprequest_post/script.js | 0 12 - 10.12.23/11_homework/index.html | 25 ++ 12 - 10.12.23/11_homework/script.js | 53 ++++ 12 - 10.12.23/11_homework/users.json | 232 ++++++++++++++++++ 12 - 10.12.23/api_nba/index.html | 17 ++ 12 - 10.12.23/api_nba/script.js | 42 ++++ 12 - 10.12.23/promise_0/index.html | 18 ++ 12 - 10.12.23/promise_0/script.js | 53 ++++ 12 - 10.12.23/promise_1 - exercise/index.html | 18 ++ 12 - 10.12.23/promise_1 - exercise/script.js | 27 ++ 12 - 10.12.23/promise_2/index.html | 17 ++ 12 - 10.12.23/promise_2/script.js | 31 +++ .../arrow_functions/index.html | 0 .../arrow_functions/script.js | 0 .../shallow_and_deep_copy/index.html | 0 .../shallow_and_deep_copy/script.js | 0 {19.11.23 => 7 - 19.11.23}/spread/index.html | 0 {19.11.23 => 7 - 19.11.23}/spread/script.js | 0 .../19.11.23 homework/index.html | 0 .../19.11.23 homework/script.js | 0 .../callback/index.html | 0 {22.11.23 => 8 - 22.11.23}/callback/script.js | 0 .../template-literal/index.html | 0 .../template-literal/script.js | 0 .../try-catch/index.html | 0 .../try-catch/script.js | 0 .../callback - eventlistener/index.html | 0 .../callback - eventlistener/script.js | 0 .../callback - fill-in/index.html | 0 .../callback - fill-in/script.js | 0 .../callback_1/index.html | 0 .../callback_1/script.js | 0 .../callback_2 - exercise/index.html | 0 .../callback_2 - exercise/script.js | 0 .../callback_3 - with parameters 1/index.html | 0 .../callback_3 - with parameters 1/script.js | 0 .../callback_3 - with parameters 2/index.html | 0 .../callback_3 - with parameters 2/script.js | 0 .../callback_3 - with parameters 3/index.html | 0 .../callback_3 - with parameters 3/script.js | 0 .../homework_try-catch/index.html | 0 .../homework_try-catch/script.js | 0 55 files changed, 533 insertions(+) rename {29.11.23 => 10 - 29.11.23}/async/index.html (100%) rename {29.11.23 => 10 - 29.11.23}/async/script.js (100%) rename {29.11.23 => 10 - 29.11.23}/async_clear_interval/index.html (100%) rename {29.11.23 => 10 - 29.11.23}/async_clear_interval/script.js (100%) rename {29.11.23 => 10 - 29.11.23}/async_exercise/index.html (100%) rename {29.11.23 => 10 - 29.11.23}/async_exercise/script.js (100%) rename {29.11.23 => 10 - 29.11.23}/xmlhttprequest/index.html (100%) rename {29.11.23 => 10 - 29.11.23}/xmlhttprequest/script.js (100%) rename {03.12.23 => 11 - 03.12.23}/xmlhttprequest/index.html (100%) rename {03.12.23 => 11 - 03.12.23}/xmlhttprequest/script.js (100%) rename {03.12.23 => 11 - 03.12.23}/xmlhttprequest_exercise/index.html (100%) rename {03.12.23 => 11 - 03.12.23}/xmlhttprequest_exercise/script.js (100%) rename {03.12.23 => 11 - 03.12.23}/xmlhttprequest_post/index.html (100%) rename {03.12.23 => 11 - 03.12.23}/xmlhttprequest_post/script.js (100%) create mode 100644 12 - 10.12.23/11_homework/index.html create mode 100644 12 - 10.12.23/11_homework/script.js create mode 100644 12 - 10.12.23/11_homework/users.json create mode 100644 12 - 10.12.23/api_nba/index.html create mode 100644 12 - 10.12.23/api_nba/script.js create mode 100644 12 - 10.12.23/promise_0/index.html create mode 100644 12 - 10.12.23/promise_0/script.js create mode 100644 12 - 10.12.23/promise_1 - exercise/index.html create mode 100644 12 - 10.12.23/promise_1 - exercise/script.js create mode 100644 12 - 10.12.23/promise_2/index.html create mode 100644 12 - 10.12.23/promise_2/script.js rename {19.11.23 => 7 - 19.11.23}/arrow_functions/index.html (100%) rename {19.11.23 => 7 - 19.11.23}/arrow_functions/script.js (100%) rename {19.11.23 => 7 - 19.11.23}/shallow_and_deep_copy/index.html (100%) rename {19.11.23 => 7 - 19.11.23}/shallow_and_deep_copy/script.js (100%) rename {19.11.23 => 7 - 19.11.23}/spread/index.html (100%) rename {19.11.23 => 7 - 19.11.23}/spread/script.js (100%) rename {22.11.23 => 8 - 22.11.23}/19.11.23 homework/index.html (100%) rename {22.11.23 => 8 - 22.11.23}/19.11.23 homework/script.js (100%) rename {22.11.23 => 8 - 22.11.23}/callback/index.html (100%) rename {22.11.23 => 8 - 22.11.23}/callback/script.js (100%) rename {22.11.23 => 8 - 22.11.23}/template-literal/index.html (100%) rename {22.11.23 => 8 - 22.11.23}/template-literal/script.js (100%) rename {22.11.23 => 8 - 22.11.23}/try-catch/index.html (100%) rename {22.11.23 => 8 - 22.11.23}/try-catch/script.js (100%) rename {26.11.23 => 9 - 26.11.23}/callback - eventlistener/index.html (100%) rename {26.11.23 => 9 - 26.11.23}/callback - eventlistener/script.js (100%) rename {26.11.23 => 9 - 26.11.23}/callback - fill-in/index.html (100%) rename {26.11.23 => 9 - 26.11.23}/callback - fill-in/script.js (100%) rename {26.11.23 => 9 - 26.11.23}/callback_1/index.html (100%) rename {26.11.23 => 9 - 26.11.23}/callback_1/script.js (100%) rename {26.11.23 => 9 - 26.11.23}/callback_2 - exercise/index.html (100%) rename {26.11.23 => 9 - 26.11.23}/callback_2 - exercise/script.js (100%) rename {26.11.23 => 9 - 26.11.23}/callback_3 - with parameters 1/index.html (100%) rename {26.11.23 => 9 - 26.11.23}/callback_3 - with parameters 1/script.js (100%) rename {26.11.23 => 9 - 26.11.23}/callback_3 - with parameters 2/index.html (100%) rename {26.11.23 => 9 - 26.11.23}/callback_3 - with parameters 2/script.js (100%) rename {26.11.23 => 9 - 26.11.23}/callback_3 - with parameters 3/index.html (100%) rename {26.11.23 => 9 - 26.11.23}/callback_3 - with parameters 3/script.js (100%) rename {26.11.23 => 9 - 26.11.23}/homework_try-catch/index.html (100%) rename {26.11.23 => 9 - 26.11.23}/homework_try-catch/script.js (100%) diff --git a/29.11.23/async/index.html b/10 - 29.11.23/async/index.html similarity index 100% rename from 29.11.23/async/index.html rename to 10 - 29.11.23/async/index.html diff --git a/29.11.23/async/script.js b/10 - 29.11.23/async/script.js similarity index 100% rename from 29.11.23/async/script.js rename to 10 - 29.11.23/async/script.js diff --git a/29.11.23/async_clear_interval/index.html b/10 - 29.11.23/async_clear_interval/index.html similarity index 100% rename from 29.11.23/async_clear_interval/index.html rename to 10 - 29.11.23/async_clear_interval/index.html diff --git a/29.11.23/async_clear_interval/script.js b/10 - 29.11.23/async_clear_interval/script.js similarity index 100% rename from 29.11.23/async_clear_interval/script.js rename to 10 - 29.11.23/async_clear_interval/script.js diff --git a/29.11.23/async_exercise/index.html b/10 - 29.11.23/async_exercise/index.html similarity index 100% rename from 29.11.23/async_exercise/index.html rename to 10 - 29.11.23/async_exercise/index.html diff --git a/29.11.23/async_exercise/script.js b/10 - 29.11.23/async_exercise/script.js similarity index 100% rename from 29.11.23/async_exercise/script.js rename to 10 - 29.11.23/async_exercise/script.js diff --git a/29.11.23/xmlhttprequest/index.html b/10 - 29.11.23/xmlhttprequest/index.html similarity index 100% rename from 29.11.23/xmlhttprequest/index.html rename to 10 - 29.11.23/xmlhttprequest/index.html diff --git a/29.11.23/xmlhttprequest/script.js b/10 - 29.11.23/xmlhttprequest/script.js similarity index 100% rename from 29.11.23/xmlhttprequest/script.js rename to 10 - 29.11.23/xmlhttprequest/script.js diff --git a/03.12.23/xmlhttprequest/index.html b/11 - 03.12.23/xmlhttprequest/index.html similarity index 100% rename from 03.12.23/xmlhttprequest/index.html rename to 11 - 03.12.23/xmlhttprequest/index.html diff --git a/03.12.23/xmlhttprequest/script.js b/11 - 03.12.23/xmlhttprequest/script.js similarity index 100% rename from 03.12.23/xmlhttprequest/script.js rename to 11 - 03.12.23/xmlhttprequest/script.js diff --git a/03.12.23/xmlhttprequest_exercise/index.html b/11 - 03.12.23/xmlhttprequest_exercise/index.html similarity index 100% rename from 03.12.23/xmlhttprequest_exercise/index.html rename to 11 - 03.12.23/xmlhttprequest_exercise/index.html diff --git a/03.12.23/xmlhttprequest_exercise/script.js b/11 - 03.12.23/xmlhttprequest_exercise/script.js similarity index 100% rename from 03.12.23/xmlhttprequest_exercise/script.js rename to 11 - 03.12.23/xmlhttprequest_exercise/script.js diff --git a/03.12.23/xmlhttprequest_post/index.html b/11 - 03.12.23/xmlhttprequest_post/index.html similarity index 100% rename from 03.12.23/xmlhttprequest_post/index.html rename to 11 - 03.12.23/xmlhttprequest_post/index.html diff --git a/03.12.23/xmlhttprequest_post/script.js b/11 - 03.12.23/xmlhttprequest_post/script.js similarity index 100% rename from 03.12.23/xmlhttprequest_post/script.js rename to 11 - 03.12.23/xmlhttprequest_post/script.js diff --git a/12 - 10.12.23/11_homework/index.html b/12 - 10.12.23/11_homework/index.html new file mode 100644 index 0000000..5b758c3 --- /dev/null +++ b/12 - 10.12.23/11_homework/index.html @@ -0,0 +1,25 @@ + + + + + + 19.11.23 + + + +

10.12.23

+

XMLHttpRequest - Homework

+ +
+ +
+ +
+ +
+ + +
+
+ + diff --git a/12 - 10.12.23/11_homework/script.js b/12 - 10.12.23/11_homework/script.js new file mode 100644 index 0000000..bef7aeb --- /dev/null +++ b/12 - 10.12.23/11_homework/script.js @@ -0,0 +1,53 @@ +let usersObj; + +// -- MODEL -- +// Function that retrieves data from server +const getUsersFromServer = () => { + const xhr = new XMLHttpRequest(); // new instance of class 'XMLHttpReqeust' + + // When a 'completed' request was called and a 'completed' response was sent back + // Here we will handle both successful server actions and unsuccessful server actions + xhr.onload = () => { + // JSON.parse() --> Convert JSON text to Javascript object + usersObj = JSON.parse(xhr.responseText); + let usersHTML = ''; + + // Create all s for all users + for (let user of usersObj) { + usersHTML += ` + + ${user.id} + ${user.name} + ${user.email} + ${user.phone} + + `; + } + + // 1. Add titles to the userHTML + // 2. Add to DOM + document.getElementById('myTable').innerHTML = usersHTML; + } + + xhr.open('GET', 'https://jsonplaceholder.typicode.com/users'); // == READ, Type: 'xhr' in 'Netowrk' tab in 'F12 - Developer Tools' + xhr.send(); +} + +// -- VIEW -- +// פונקציה שמקבלת מערך של אובייקטים של משתמשים ומייצרת טבלה להציג אותם +// Function that recieves array of JS objects and creates a table with the information +const createTableFromUsers = (arrUsers) => { + +} + +// -- CONTROLLER -- מתכלל הפעולות בתוכנה +const displayUsers = () => { + // 1. Call server + const arrUsers = getUsersFromServer(); + + // 2. Update UI + createTableFromUsers(arrUsers); +} + +// נחבר את אירוע הלחיצה לפונקציית קבלת המידע מהשרת +document.getElementById('btnLoad').addEventListener('click', displayUsers); \ No newline at end of file diff --git a/12 - 10.12.23/11_homework/users.json b/12 - 10.12.23/11_homework/users.json new file mode 100644 index 0000000..a1effe4 --- /dev/null +++ b/12 - 10.12.23/11_homework/users.json @@ -0,0 +1,232 @@ +[ + { + "id": 1, + "name": "Leanne Graham", + "username": "Bret", + "email": "Sincere@april.biz", + "address": { + "street": "Kulas Light", + "suite": "Apt. 556", + "city": "Gwenborough", + "zipcode": "92998-3874", + "geo": { + "lat": "-37.3159", + "lng": "81.1496" + } + }, + "phone": "1-770-736-8031 x56442", + "website": "hildegard.org", + "company": { + "name": "Romaguera-Crona", + "catchPhrase": "Multi-layered client-server neural-net", + "bs": "harness real-time e-markets" + } + }, + { + "id": 2, + "name": "Ervin Howell", + "username": "Antonette", + "email": "Shanna@melissa.tv", + "address": { + "street": "Victor Plains", + "suite": "Suite 879", + "city": "Wisokyburgh", + "zipcode": "90566-7771", + "geo": { + "lat": "-43.9509", + "lng": "-34.4618" + } + }, + "phone": "010-692-6593 x09125", + "website": "anastasia.net", + "company": { + "name": "Deckow-Crist", + "catchPhrase": "Proactive didactic contingency", + "bs": "synergize scalable supply-chains" + } + }, + { + "id": 3, + "name": "Clementine Bauch", + "username": "Samantha", + "email": "Nathan@yesenia.net", + "address": { + "street": "Douglas Extension", + "suite": "Suite 847", + "city": "McKenziehaven", + "zipcode": "59590-4157", + "geo": { + "lat": "-68.6102", + "lng": "-47.0653" + } + }, + "phone": "1-463-123-4447", + "website": "ramiro.info", + "company": { + "name": "Romaguera-Jacobson", + "catchPhrase": "Face to face bifurcated interface", + "bs": "e-enable strategic applications" + } + }, + { + "id": 4, + "name": "Patricia Lebsack", + "username": "Karianne", + "email": "Julianne.OConner@kory.org", + "address": { + "street": "Hoeger Mall", + "suite": "Apt. 692", + "city": "South Elvis", + "zipcode": "53919-4257", + "geo": { + "lat": "29.4572", + "lng": "-164.2990" + } + }, + "phone": "493-170-9623 x156", + "website": "kale.biz", + "company": { + "name": "Robel-Corkery", + "catchPhrase": "Multi-tiered zero tolerance productivity", + "bs": "transition cutting-edge web services" + } + }, + { + "id": 5, + "name": "Chelsey Dietrich", + "username": "Kamren", + "email": "Lucio_Hettinger@annie.ca", + "address": { + "street": "Skiles Walks", + "suite": "Suite 351", + "city": "Roscoeview", + "zipcode": "33263", + "geo": { + "lat": "-31.8129", + "lng": "62.5342" + } + }, + "phone": "(254)954-1289", + "website": "demarco.info", + "company": { + "name": "Keebler LLC", + "catchPhrase": "User-centric fault-tolerant solution", + "bs": "revolutionize end-to-end systems" + } + }, + { + "id": 6, + "name": "Mrs. Dennis Schulist", + "username": "Leopoldo_Corkery", + "email": "Karley_Dach@jasper.info", + "address": { + "street": "Norberto Crossing", + "suite": "Apt. 950", + "city": "South Christy", + "zipcode": "23505-1337", + "geo": { + "lat": "-71.4197", + "lng": "71.7478" + } + }, + "phone": "1-477-935-8478 x6430", + "website": "ola.org", + "company": { + "name": "Considine-Lockman", + "catchPhrase": "Synchronised bottom-line interface", + "bs": "e-enable innovative applications" + } + }, + { + "id": 7, + "name": "Kurtis Weissnat", + "username": "Elwyn.Skiles", + "email": "Telly.Hoeger@billy.biz", + "address": { + "street": "Rex Trail", + "suite": "Suite 280", + "city": "Howemouth", + "zipcode": "58804-1099", + "geo": { + "lat": "24.8918", + "lng": "21.8984" + } + }, + "phone": "210.067.6132", + "website": "elvis.io", + "company": { + "name": "Johns Group", + "catchPhrase": "Configurable multimedia task-force", + "bs": "generate enterprise e-tailers" + } + }, + { + "id": 8, + "name": "Nicholas Runolfsdottir V", + "username": "Maxime_Nienow", + "email": "Sherwood@rosamond.me", + "address": { + "street": "Ellsworth Summit", + "suite": "Suite 729", + "city": "Aliyaview", + "zipcode": "45169", + "geo": { + "lat": "-14.3990", + "lng": "-120.7677" + } + }, + "phone": "586.493.6943 x140", + "website": "jacynthe.com", + "company": { + "name": "Abernathy Group", + "catchPhrase": "Implemented secondary concept", + "bs": "e-enable extensible e-tailers" + } + }, + { + "id": 9, + "name": "Glenna Reichert", + "username": "Delphine", + "email": "Chaim_McDermott@dana.io", + "address": { + "street": "Dayna Park", + "suite": "Suite 449", + "city": "Bartholomebury", + "zipcode": "76495-3109", + "geo": { + "lat": "24.6463", + "lng": "-168.8889" + } + }, + "phone": "(775)976-6794 x41206", + "website": "conrad.com", + "company": { + "name": "Yost and Sons", + "catchPhrase": "Switchable contextually-based project", + "bs": "aggregate real-time technologies" + } + }, + { + "id": 10, + "name": "Clementina DuBuque", + "username": "Moriah.Stanton", + "email": "Rey.Padberg@karina.biz", + "address": { + "street": "Kattie Turnpike", + "suite": "Suite 198", + "city": "Lebsackbury", + "zipcode": "31428-2261", + "geo": { + "lat": "-38.2386", + "lng": "57.2232" + } + }, + "phone": "024-648-3804", + "website": "ambrose.net", + "company": { + "name": "Hoeger LLC", + "catchPhrase": "Centralized empowering task-force", + "bs": "target end-to-end models" + } + } +] \ No newline at end of file diff --git a/12 - 10.12.23/api_nba/index.html b/12 - 10.12.23/api_nba/index.html new file mode 100644 index 0000000..691b5a3 --- /dev/null +++ b/12 - 10.12.23/api_nba/index.html @@ -0,0 +1,17 @@ + + + + + + 19.11.23 + + + +

19.11.23

+

NBA test

+
+
+ +
+ + diff --git a/12 - 10.12.23/api_nba/script.js b/12 - 10.12.23/api_nba/script.js new file mode 100644 index 0000000..c53f535 --- /dev/null +++ b/12 - 10.12.23/api_nba/script.js @@ -0,0 +1,42 @@ + +// Get players +function getPlayers() { + // 1. Create the XMLHttpRequest object + const xhr = new XMLHttpRequest(); // new instance of class 'XMLHttpReqeust' + + // 2. Define the successful response function + // Make sure to handle the most common ones, 200, 201, 204 + xhr.onload = () => { + // JSON.parse() --> Convert JSON text to Javascript object + const data = JSON.parse(xhr.responseText); + + // Iterate / loop over all attributes in the 'responseObj' + document.getElementById("app").innerHTML = data; + } + + // 3. Define the error response function + // Make sure to handle at least the most common ones, 401, 403, 404, 500 + xhr.onerror = () => {} // Handling errors + + // 4. Define the abort response function + xhr.onabort = () => {} // Handling aborted operations (if the operation takes a long time) + + // 5. Define the abort response function + xhr.onprogress = () => {} // Handling period updates, e.g. updating a progress bar in the UI + + // 6. Define the GET parameters (ONLY RELEVANT TO GET REQUESTS) + var params = "team=1&season=2023"; + + // 7. Open the connection to the remote server + xhr.open('GET', `https://api-nba-v1.p.rapidapi.com/players?${params}`); // == READ, Type: 'xhr' in 'Netowrk' tab in 'F12 - Developer Tools' + + // 8. Define specific headers to include in the REQUEST, e.g. authentication key + xhr.setRequestHeader('X-RapidAPI-Key', 'r66M9SM0SFmshzf6c9KbVDBwXlgVp1pikIxjsn1HaQtduybhz2'); + xhr.setRequestHeader('X-RapidAPI-Host', 'api-nba-v1.p.rapidapi.com'); + + // 9. Make the call to the server + xhr.send(); +} + +// 10. Attach the function that calls the server to an event in the UI +document.getElementById('getPlayers').addEventListener('click', getPlayers); \ No newline at end of file diff --git a/12 - 10.12.23/promise_0/index.html b/12 - 10.12.23/promise_0/index.html new file mode 100644 index 0000000..c8ff660 --- /dev/null +++ b/12 - 10.12.23/promise_0/index.html @@ -0,0 +1,18 @@ + + + + + + 19.11.23 + + + +

19.11.23

+

Promise

+ +
+
+ +
+ + diff --git a/12 - 10.12.23/promise_0/script.js b/12 - 10.12.23/promise_0/script.js new file mode 100644 index 0000000..b91febd --- /dev/null +++ b/12 - 10.12.23/promise_0/script.js @@ -0,0 +1,53 @@ +// function getNumber() { +// setTimeout(() => { +// const myNum = Math.random(); +// if (myNum > 0.5) { +// document.getElementById('app').innerHTML = `${myNum}: Success`; +// } else { +// document.getElementById('app').innerHTML = `${myNum}: Error`; +// } +// }, 2000); +// }; + + +// function getNumber() { +// setTimeout(() => { +// const myNum = Math.random(); +// if (myNum > 0.5) { +// itWorked(myNum); +// } else { +// myError(myNum); +// } +// }, 2000); +// }; + +// function itWorked(myNum) { +// document.getElementById('app').innerHTML = `${myNum}: Success`; +// } + +// function myError(myNum) { +// document.getElementById('app').innerHTML = `${myNum}: Error`; +// } + +function getNumber() { + const myPromise = new Promise((resolve, reject) => { + // Inside this function, you perform thSe asynchronous operation. + // In the case of XHR, you would make the HTTP request here. + setTimeout(() => { + const myNum = Math.random(); + if (myNum > 0.5) { + resolve(myNum); + } else { + reject(myNum); + } + }, 2000); + }); + + myPromise.then((data) => { + document.getElementById('app').innerHTML = `${data}: Success`; + }).catch((error) => { + document.getElementById('app').innerHTML = `${error}: Error`; + }); +} + +document.getElementById('start').addEventListener('click', getNumber); \ No newline at end of file diff --git a/12 - 10.12.23/promise_1 - exercise/index.html b/12 - 10.12.23/promise_1 - exercise/index.html new file mode 100644 index 0000000..c8ff660 --- /dev/null +++ b/12 - 10.12.23/promise_1 - exercise/index.html @@ -0,0 +1,18 @@ + + + + + + 19.11.23 + + + +

19.11.23

+

Promise

+ +
+
+ +
+ + diff --git a/12 - 10.12.23/promise_1 - exercise/script.js b/12 - 10.12.23/promise_1 - exercise/script.js new file mode 100644 index 0000000..2db6df0 --- /dev/null +++ b/12 - 10.12.23/promise_1 - exercise/script.js @@ -0,0 +1,27 @@ +function getName() { + const myPromise = new Promise((resolve, reject) => { + // Inside this function, you perform thSe asynchronous operation. + // In the case of XHR, you would make the HTTP request here. + setTimeout(() => { + const name = prompt('Please enter your name'); + + if (name === '-1') { + reject(name); + } else { + resolve(name); + } + }, 2000); + }); + + const successFunc = (data) => { + alert(`${data}: Success`); + } + + const errorFunc = (error) => { + alert(`${error}: Error`); + } + + myPromise.then(successFunc).catch(errorFunc); +} + +document.getElementById('start').addEventListener('click', getName); \ No newline at end of file diff --git a/12 - 10.12.23/promise_2/index.html b/12 - 10.12.23/promise_2/index.html new file mode 100644 index 0000000..0ebccc1 --- /dev/null +++ b/12 - 10.12.23/promise_2/index.html @@ -0,0 +1,17 @@ + + + + + + 19.11.23 + + + +

19.11.23

+

Promise

+
+
+ +
+ + diff --git a/12 - 10.12.23/promise_2/script.js b/12 - 10.12.23/promise_2/script.js new file mode 100644 index 0000000..586a4e5 --- /dev/null +++ b/12 - 10.12.23/promise_2/script.js @@ -0,0 +1,31 @@ +const myPromise = new Promise((resolve, reject) => { + // Inside this function, you perform the asynchronous operation. + // In the case of XHR, you would make the HTTP request here. + const xhr = new XMLHttpRequest(); + xhr.open('GET', 'https://jsonplaceholder.typicode.com/users/1', true); + + xhr.onload = () => { + if (xhr.status === 200) { + resolve(xhr.responseText); // Resolve with the response data. + } else { + reject('Error: Unable to fetch data'); // Reject with an error message. + } + }; + + xhr.onerror = () => { + reject('Network error'); // Reject if there's a network error. + }; + + xhr.send(); + }); + +myPromise + .then((data) => { + // This function runs if the Promise is resolved successfully. + console.log('Data received:', data); + }) + .catch((error) => { + // This function runs if the Promise is rejected with an error. + console.error('Error:', error); + }); + \ No newline at end of file diff --git a/19.11.23/arrow_functions/index.html b/7 - 19.11.23/arrow_functions/index.html similarity index 100% rename from 19.11.23/arrow_functions/index.html rename to 7 - 19.11.23/arrow_functions/index.html diff --git a/19.11.23/arrow_functions/script.js b/7 - 19.11.23/arrow_functions/script.js similarity index 100% rename from 19.11.23/arrow_functions/script.js rename to 7 - 19.11.23/arrow_functions/script.js diff --git a/19.11.23/shallow_and_deep_copy/index.html b/7 - 19.11.23/shallow_and_deep_copy/index.html similarity index 100% rename from 19.11.23/shallow_and_deep_copy/index.html rename to 7 - 19.11.23/shallow_and_deep_copy/index.html diff --git a/19.11.23/shallow_and_deep_copy/script.js b/7 - 19.11.23/shallow_and_deep_copy/script.js similarity index 100% rename from 19.11.23/shallow_and_deep_copy/script.js rename to 7 - 19.11.23/shallow_and_deep_copy/script.js diff --git a/19.11.23/spread/index.html b/7 - 19.11.23/spread/index.html similarity index 100% rename from 19.11.23/spread/index.html rename to 7 - 19.11.23/spread/index.html diff --git a/19.11.23/spread/script.js b/7 - 19.11.23/spread/script.js similarity index 100% rename from 19.11.23/spread/script.js rename to 7 - 19.11.23/spread/script.js diff --git a/22.11.23/19.11.23 homework/index.html b/8 - 22.11.23/19.11.23 homework/index.html similarity index 100% rename from 22.11.23/19.11.23 homework/index.html rename to 8 - 22.11.23/19.11.23 homework/index.html diff --git a/22.11.23/19.11.23 homework/script.js b/8 - 22.11.23/19.11.23 homework/script.js similarity index 100% rename from 22.11.23/19.11.23 homework/script.js rename to 8 - 22.11.23/19.11.23 homework/script.js diff --git a/22.11.23/callback/index.html b/8 - 22.11.23/callback/index.html similarity index 100% rename from 22.11.23/callback/index.html rename to 8 - 22.11.23/callback/index.html diff --git a/22.11.23/callback/script.js b/8 - 22.11.23/callback/script.js similarity index 100% rename from 22.11.23/callback/script.js rename to 8 - 22.11.23/callback/script.js diff --git a/22.11.23/template-literal/index.html b/8 - 22.11.23/template-literal/index.html similarity index 100% rename from 22.11.23/template-literal/index.html rename to 8 - 22.11.23/template-literal/index.html diff --git a/22.11.23/template-literal/script.js b/8 - 22.11.23/template-literal/script.js similarity index 100% rename from 22.11.23/template-literal/script.js rename to 8 - 22.11.23/template-literal/script.js diff --git a/22.11.23/try-catch/index.html b/8 - 22.11.23/try-catch/index.html similarity index 100% rename from 22.11.23/try-catch/index.html rename to 8 - 22.11.23/try-catch/index.html diff --git a/22.11.23/try-catch/script.js b/8 - 22.11.23/try-catch/script.js similarity index 100% rename from 22.11.23/try-catch/script.js rename to 8 - 22.11.23/try-catch/script.js diff --git a/26.11.23/callback - eventlistener/index.html b/9 - 26.11.23/callback - eventlistener/index.html similarity index 100% rename from 26.11.23/callback - eventlistener/index.html rename to 9 - 26.11.23/callback - eventlistener/index.html diff --git a/26.11.23/callback - eventlistener/script.js b/9 - 26.11.23/callback - eventlistener/script.js similarity index 100% rename from 26.11.23/callback - eventlistener/script.js rename to 9 - 26.11.23/callback - eventlistener/script.js diff --git a/26.11.23/callback - fill-in/index.html b/9 - 26.11.23/callback - fill-in/index.html similarity index 100% rename from 26.11.23/callback - fill-in/index.html rename to 9 - 26.11.23/callback - fill-in/index.html diff --git a/26.11.23/callback - fill-in/script.js b/9 - 26.11.23/callback - fill-in/script.js similarity index 100% rename from 26.11.23/callback - fill-in/script.js rename to 9 - 26.11.23/callback - fill-in/script.js diff --git a/26.11.23/callback_1/index.html b/9 - 26.11.23/callback_1/index.html similarity index 100% rename from 26.11.23/callback_1/index.html rename to 9 - 26.11.23/callback_1/index.html diff --git a/26.11.23/callback_1/script.js b/9 - 26.11.23/callback_1/script.js similarity index 100% rename from 26.11.23/callback_1/script.js rename to 9 - 26.11.23/callback_1/script.js diff --git a/26.11.23/callback_2 - exercise/index.html b/9 - 26.11.23/callback_2 - exercise/index.html similarity index 100% rename from 26.11.23/callback_2 - exercise/index.html rename to 9 - 26.11.23/callback_2 - exercise/index.html diff --git a/26.11.23/callback_2 - exercise/script.js b/9 - 26.11.23/callback_2 - exercise/script.js similarity index 100% rename from 26.11.23/callback_2 - exercise/script.js rename to 9 - 26.11.23/callback_2 - exercise/script.js diff --git a/26.11.23/callback_3 - with parameters 1/index.html b/9 - 26.11.23/callback_3 - with parameters 1/index.html similarity index 100% rename from 26.11.23/callback_3 - with parameters 1/index.html rename to 9 - 26.11.23/callback_3 - with parameters 1/index.html diff --git a/26.11.23/callback_3 - with parameters 1/script.js b/9 - 26.11.23/callback_3 - with parameters 1/script.js similarity index 100% rename from 26.11.23/callback_3 - with parameters 1/script.js rename to 9 - 26.11.23/callback_3 - with parameters 1/script.js diff --git a/26.11.23/callback_3 - with parameters 2/index.html b/9 - 26.11.23/callback_3 - with parameters 2/index.html similarity index 100% rename from 26.11.23/callback_3 - with parameters 2/index.html rename to 9 - 26.11.23/callback_3 - with parameters 2/index.html diff --git a/26.11.23/callback_3 - with parameters 2/script.js b/9 - 26.11.23/callback_3 - with parameters 2/script.js similarity index 100% rename from 26.11.23/callback_3 - with parameters 2/script.js rename to 9 - 26.11.23/callback_3 - with parameters 2/script.js diff --git a/26.11.23/callback_3 - with parameters 3/index.html b/9 - 26.11.23/callback_3 - with parameters 3/index.html similarity index 100% rename from 26.11.23/callback_3 - with parameters 3/index.html rename to 9 - 26.11.23/callback_3 - with parameters 3/index.html diff --git a/26.11.23/callback_3 - with parameters 3/script.js b/9 - 26.11.23/callback_3 - with parameters 3/script.js similarity index 100% rename from 26.11.23/callback_3 - with parameters 3/script.js rename to 9 - 26.11.23/callback_3 - with parameters 3/script.js diff --git a/26.11.23/homework_try-catch/index.html b/9 - 26.11.23/homework_try-catch/index.html similarity index 100% rename from 26.11.23/homework_try-catch/index.html rename to 9 - 26.11.23/homework_try-catch/index.html diff --git a/26.11.23/homework_try-catch/script.js b/9 - 26.11.23/homework_try-catch/script.js similarity index 100% rename from 26.11.23/homework_try-catch/script.js rename to 9 - 26.11.23/homework_try-catch/script.js