diff --git a/callback.js b/callback.js new file mode 100644 index 0000000..4c8a152 --- /dev/null +++ b/callback.js @@ -0,0 +1,16 @@ +let batorzsido = false; + + +let bator = () => { + console.log("Ez a zsidó a templomban is fingik."); +} + +let gyava = () => { + console.log("Ez a zsidó nem fingik a templomban"); +} + +let zsidoeldont = (batorzsido) =>{ + batorzsido ? bator() : gyava(); +} + +zsidoeldont(batorzsido); \ No newline at end of file diff --git a/promise.js b/promise.js new file mode 100644 index 0000000..cae7e58 --- /dev/null +++ b/promise.js @@ -0,0 +1,95 @@ +/* +let p = new Promise((resolve, reject) => { + let a = 1 + 1 + 1 + if (a == 2){ + resolve("Success") + } else { + reject("failed") + } +}) + +p +.then((message) =>{ + console.log("This is in the then" + message) +}).catch((message) => { + console.log("in the catch" + message) +}) +*/ + +const userLeft = false; +const userWatchingCatMeme = false; + +function watchTutorialCallback(callback, errorCallback){ + if (userLeft){ + errorCallback({ + name: "User Left", + message: ":(" + }) + } else if(userWatchingCatMeme) { + errorCallback({ + name: "User Watching Cat Meme", + message: "Cats are cute" + }) + } else { + callback("Thumbs up and subscribe") + } +} + + + +watchTutorialCallback(function (message) { + console.log(`Success: ${message}`) +}, (error) => { + console.log(`${error.name}: ${error.message}`) +} +) + +function watchTutorialPromise(){ + return new Promise((resolve, reject) => { + if (userLeft){ + reject({ + name: "User Left", + message: ":(" + }) + } else if(userWatchingCatMeme) { + reject({ + name: "User Watching Cat Meme", + message: "Cats are cute" + }) + } else { + resolve("Thumbs up and subscribe") + } + }) +} + +watchTutorialPromise().then((message) => { + console.log(`Success: ${message}`) +}).catch((error) => { + console.log(`${error.name}: ${error.message}`) +}) + + +let prom1 = new Promise((resolve, reject) => { + setTimeout(() => { + resolve("ASD") + }, 2000) +}) + +let prom2 = new Promise((resolve, reject) => { + resolve("ASD2") +}) + +let prom3 = new Promise((resolve, reject) => { + resolve("ASD3") +}) + +Promise.all( + [ + prom1, + prom2, + prom3 + ] +).then((messages) => { + console.log(messages) +}) + diff --git a/promise2.js b/promise2.js new file mode 100644 index 0000000..9e22cab --- /dev/null +++ b/promise2.js @@ -0,0 +1,18 @@ +let batorzsido = false; + +let myPromise = new Promise((resolve, reject) => { + setTimeout(() => { + if(batorzsido){ + resolve("Ez a zsidó templomban is fingik"); + } + reject("Ez a zsidó nem fingik a templomban"); + }, 2000); +}) + +//setTimeout(asd, 3000); + +function asd(){ + myPromise.then(result => {console.log(result);}).catch(error => {console.log(error);}); +} + +asd();