From 179f05124ea6184fa6577b7d2391eba081715596 Mon Sep 17 00:00:00 2001 From: Ishad Anshar <49803495+ansharreaper@users.noreply.github.com> Date: Fri, 1 Sep 2023 02:20:53 +0700 Subject: [PATCH 1/5] Menambah File Promise-Based.js Menambah file Javascript kuis dicoding tahun 2023 yang kuisnya bernama Kuis Koding: Mengubah Fungsi Asynchronous Callback-Based Menjadi Promise-Based --- Promise-Based.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Promise-Based.js diff --git a/Promise-Based.js b/Promise-Based.js new file mode 100644 index 0000000..10e9f93 --- /dev/null +++ b/Promise-Based.js @@ -0,0 +1,29 @@ +const {promisify} = require('util'); + +function getProvinces(countryId, callback) +{ + setTimeout(() => + { + if (countryId === 'id') + { + callback(null, + [ + { id: 'id-jk', name: 'Jakarta' }, + { id: 'id-bt', name: 'Banten' }, + { id: 'id-jr', name: 'Jawa Barat' }, + ]); + + return; + } + + callback(new Error('Country not found'), null); + }, 1000); +} + +const getProvincesPromise = promisify(getProvinces); + +getProvincesPromise('id') +.then (Provinces => console.log(Provinces)) +.catch (err => console.log(err.message)); + +module.exports = { getProvinces: getProvincesPromise}; From 1effeb27b89777a7a3765082bb51ad3b0e89713b Mon Sep 17 00:00:00 2001 From: Ishad Anshar <49803495+ansharreaper@users.noreply.github.com> Date: Fri, 1 Sep 2023 02:22:10 +0700 Subject: [PATCH 2/5] Added Files Kuis Koding: Mengubah Fungsi Asynchronous Callback-Based Menjadi Promise-Based From 1c32d3e81ebe494105e8bdcb5aef5e25f658d052 Mon Sep 17 00:00:00 2001 From: Ishad Anshar <49803495+ansharreaper@users.noreply.github.com> Date: Fri, 1 Sep 2023 02:23:46 +0700 Subject: [PATCH 3/5] Delete Promise-Based.js --- Promise-Based.js | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 Promise-Based.js diff --git a/Promise-Based.js b/Promise-Based.js deleted file mode 100644 index 10e9f93..0000000 --- a/Promise-Based.js +++ /dev/null @@ -1,29 +0,0 @@ -const {promisify} = require('util'); - -function getProvinces(countryId, callback) -{ - setTimeout(() => - { - if (countryId === 'id') - { - callback(null, - [ - { id: 'id-jk', name: 'Jakarta' }, - { id: 'id-bt', name: 'Banten' }, - { id: 'id-jr', name: 'Jawa Barat' }, - ]); - - return; - } - - callback(new Error('Country not found'), null); - }, 1000); -} - -const getProvincesPromise = promisify(getProvinces); - -getProvincesPromise('id') -.then (Provinces => console.log(Provinces)) -.catch (err => console.log(err.message)); - -module.exports = { getProvinces: getProvincesPromise}; From 8c1916ee507ee4e1cca910152e2d984140a5065f Mon Sep 17 00:00:00 2001 From: Ishad Anshar <49803495+ansharreaper@users.noreply.github.com> Date: Fri, 1 Sep 2023 02:24:31 +0700 Subject: [PATCH 4/5] Added Files Kuis Koding: Mengubah Fungsi Asynchronous Callback-Based Menjadi Promise-Based --- Promise-Based.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Promise-Based.js diff --git a/Promise-Based.js b/Promise-Based.js new file mode 100644 index 0000000..10e9f93 --- /dev/null +++ b/Promise-Based.js @@ -0,0 +1,29 @@ +const {promisify} = require('util'); + +function getProvinces(countryId, callback) +{ + setTimeout(() => + { + if (countryId === 'id') + { + callback(null, + [ + { id: 'id-jk', name: 'Jakarta' }, + { id: 'id-bt', name: 'Banten' }, + { id: 'id-jr', name: 'Jawa Barat' }, + ]); + + return; + } + + callback(new Error('Country not found'), null); + }, 1000); +} + +const getProvincesPromise = promisify(getProvinces); + +getProvincesPromise('id') +.then (Provinces => console.log(Provinces)) +.catch (err => console.log(err.message)); + +module.exports = { getProvinces: getProvincesPromise}; From 1266830b04ec6212cfa627ef36531c68cb6486fd Mon Sep 17 00:00:00 2001 From: Ishad Anshar <49803495+ansharreaper@users.noreply.github.com> Date: Fri, 1 Sep 2023 02:47:23 +0700 Subject: [PATCH 5/5] Added Files Kuis Coding : Asynchronous Proses secara Berantai --- AsynchronousBerantai.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 AsynchronousBerantai.js diff --git a/AsynchronousBerantai.js b/AsynchronousBerantai.js new file mode 100644 index 0000000..43d523a --- /dev/null +++ b/AsynchronousBerantai.js @@ -0,0 +1,18 @@ +const { buyTollRoadCard, topUpBalance, useTollRoad } = require('./utils'); + +async function getTollAccess() +{ + try + { + const buy = await buyTollRoadCard(25); + const topUp = await topUpBalance(buy, 10); + const use = await useTollRoad(topUp); + } + + catch(error) + { + console.log(error.message); + } +} + +getTollAccess();