From aab12a9661f4735570cc61da84e47b3ed28336df Mon Sep 17 00:00:00 2001 From: Ervan Adetya Date: Fri, 23 Feb 2018 11:02:05 +0700 Subject: [PATCH] AMEN --- async/index.js | 53 ++++++++++++++++++++++++++++++++++------ oop/classAutoBot.js | 14 +++++++++++ oop/classBaymax.js | 14 +++++++++++ oop/classRobot.js | 10 ++++++++ oop/classRobotFactory.js | 18 ++++++++++++++ oop/classWallE.js | 14 +++++++++++ oop/index.js | 18 ++++++++++++++ query/Answer.txt | 23 +++++++++++++++++ 8 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 oop/classAutoBot.js create mode 100644 oop/classBaymax.js create mode 100644 oop/classRobot.js create mode 100644 oop/classRobotFactory.js create mode 100644 oop/classWallE.js create mode 100644 oop/index.js create mode 100644 query/Answer.txt diff --git a/async/index.js b/async/index.js index 77df3b7..e811293 100644 --- a/async/index.js +++ b/async/index.js @@ -17,8 +17,33 @@ class RNG { return result; } + + static gatchaRoll(times, callback) { + let maxVal = 0; + for(let i=0; i0) { + RNG.gatchaRoll(times, function(maxVal) { + resolve(maxVal) + }); + } + else reject(); + }); + } } +// RNG.gatchaRoll(2, viewGachaResult); +// RNG.gatchaRollPromise(2) + function viewGachaResult(best) { console.log(`YOUR BEST GATCHA ROLL RESULT IS ${best}`); } @@ -27,25 +52,37 @@ function viewGachaFailure() { console.log('YAKIN NGGAK MAU NGE-ROLL?'); } -// RELEASE 0 TEST CASES +// // RELEASE 0 TEST CASES RNG.gatchaRoll(5, function(result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik RNG.gatchaRoll(1, function(result) { viewGachaResult(result) }); // output log sesuai hasil random terbaik RNG.gatchaRoll(0, function(result) { viewGachaResult(result) }); // output: 0 -// RELEASE 1 TEST CASES +// // RELEASE 1 TEST CASES RNG.gatchaRollPromise(5) .then(function(result) { viewGachaResult(result) }) - .catch(function(err) { viewGachaFailure() }; + .catch(function(err) { viewGachaFailure() }); -// akan menampilkan di log: YOUR BEST GATCHA ROLL RESULT IS +// // akan menampilkan di log: YOUR BEST GATCHA ROLL RESULT IS RNG.gatchaRollPromise(0) .then(function(result) { viewGachaResult(result) }) - .catch(function(err) { viewGachaFailure() }; + .catch(function(err) { viewGachaFailure() }); -// akan menampilkan di log: YAKIN NGGAK MAU NGE-ROLL? +// // akan menampilkan di log: YAKIN NGGAK MAU NGE-ROLL? -// RELEASE 2 PROMISE(S) +// // RELEASE 2 PROMISE(S) -// code here... \ No newline at end of file +// // code here... +RNG.gatchaRollPromise(1) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(2);}) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(3);}) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(4);}) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(5);}) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(6);}) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(7);}) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(8);}) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(9);}) + .then(function(result) {viewGachaResult(result);return RNG.gatchaRollPromise(10);}) + .then(function(result) {viewGachaResult(result);return reject();}) + .catch(function(err) {console.log(`cape ngeroll 10 kali`)}); \ No newline at end of file diff --git a/oop/classAutoBot.js b/oop/classAutoBot.js new file mode 100644 index 0000000..6af857b --- /dev/null +++ b/oop/classAutoBot.js @@ -0,0 +1,14 @@ +'use strict' +const Robot = require('./classRobot'); + +class AutoBot extends Robot { + constructor() { + super('AutoBot', 'defenders') + } + + defend() { + console.log(`AutoBot, let's roll!`) + } +} + +module.exports = AutoBot; \ No newline at end of file diff --git a/oop/classBaymax.js b/oop/classBaymax.js new file mode 100644 index 0000000..48febc3 --- /dev/null +++ b/oop/classBaymax.js @@ -0,0 +1,14 @@ +'use strict' +const Robot = require('./classRobot'); + +class BayMax extends Robot { + constructor() { + super('Baymax', 'medic') + } + + heal() { + console.log(`Hi, I am BayMax, how may I help you?`) + } +} + +module.exports = BayMax; \ No newline at end of file diff --git a/oop/classRobot.js b/oop/classRobot.js new file mode 100644 index 0000000..393e6fd --- /dev/null +++ b/oop/classRobot.js @@ -0,0 +1,10 @@ +'use strict' + +class Robot { + constructor(name, purpose) { + this.name = name, + this.purpose = purpose + } +} + +module.exports = Robot; \ No newline at end of file diff --git a/oop/classRobotFactory.js b/oop/classRobotFactory.js new file mode 100644 index 0000000..d089fe0 --- /dev/null +++ b/oop/classRobotFactory.js @@ -0,0 +1,18 @@ +'use strict' +const WallE = require('./classWallE'); +const BayMax = require('./classBaymax'); +const AutoBot = require('./classAutoBot'); + +class RobotFactory{ + static produceRobot(type, qty) { + let robots = []; + for(let i = 0; i