diff --git a/README.md b/README.md deleted file mode 100644 index 8c0f25b2..00000000 --- a/README.md +++ /dev/null @@ -1,10 +0,0 @@ -## Modern JavaScript - Novice to Ninja -All lecture files from the Modern JavaScript (Novice to Ninja) course on Udemy. - -### How to use this repository - -Each lesson in the course has it's own branch in the repository. To see the code for a specific lesson, just select that branch from the branch drop-down (top-left). E.g. The lesson-20 branch contains the final code for lesson 20 in the course. - -**Course link:** [Modern JavaScript - Novice to Ninja](https://pages.github.com/) - - diff --git a/chapter_12/index.html b/chapter_12/index.html new file mode 100644 index 00000000..8266e47c --- /dev/null +++ b/chapter_12/index.html @@ -0,0 +1,14 @@ + + + + + + Asynchronous JavaScript + + + +

Async JavaScript

+ + + + \ No newline at end of file diff --git a/chapter_12/json/luigi.json b/chapter_12/json/luigi.json new file mode 100644 index 00000000..0a7cdf67 --- /dev/null +++ b/chapter_12/json/luigi.json @@ -0,0 +1,5 @@ +[ + {"text": "do the plumming", "author": "Luigi"}, + {"text": "avoid mario", "author": "Luigi"}, + {"text": "go kart racing", "author": "Luigi"} +] \ No newline at end of file diff --git a/chapter_12/json/mario.json b/chapter_12/json/mario.json new file mode 100644 index 00000000..5ab76086 --- /dev/null +++ b/chapter_12/json/mario.json @@ -0,0 +1,5 @@ +[ + {"text": "make fun of luigi", "author": "Mario"}, + {"text": "rescue peach (again)", "author": "Mario"}, + {"text": "go kart racing", "author": "Mario"} +] \ No newline at end of file diff --git a/chapter_12/json/shaun.json b/chapter_12/json/shaun.json new file mode 100644 index 00000000..838ef9af --- /dev/null +++ b/chapter_12/json/shaun.json @@ -0,0 +1,5 @@ +[ + {"text": "play mariokart", "author": "Shaun"}, + {"text": "buy some bread", "author": "Shaun"}, + {"text": "take a nap", "author": "Shaun"} +] \ No newline at end of file diff --git a/chapter_12/sandbox.js b/chapter_12/sandbox.js new file mode 100644 index 00000000..17b3d6a6 --- /dev/null +++ b/chapter_12/sandbox.js @@ -0,0 +1,29 @@ +const getTodos = (resource, callback) => { + + const request = new XMLHttpRequest(); + + request.addEventListener('readystatechange', () => { + + if(request.readyState === 4 && request.status === 200){ + const data = JSON.parse(request.responseText); + callback(undefined, data); + } else if (request.readyState === 4){ + callback('could not fetch the data', undefined); + } + + }); + + request.open('GET', resource); + request.send(); + +}; + +getTodos('json/luigi.json', (err, data) => { + console.log(data); + getTodos('json/mario.json', (err, data) => { + console.log(data); + getTodos('json/shaun.json', (err, data) => { + console.log(data); + }); + }); +}); \ No newline at end of file