Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMEN #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

AMEN #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,33 @@ class RNG {

return result;
}

static gatchaRoll(times, callback) {
let maxVal = 0;
for(let i=0; i<times; i++) {
let rollRes = RNG.roll();
maxVal<rollRes ? maxVal=rollRes: maxVal;
}
setTimeout(function() {
callback(maxVal)
}, 1000);
}

static gatchaRollPromise(times) {
return new Promise(function(resolve, reject) {
if(times>0) {
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}`);
}
Expand All @@ -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 <angka antara 1-5>
// // akan menampilkan di log: YOUR BEST GATCHA ROLL RESULT IS <angka antara 1-5>

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...
// // 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`)});
14 changes: 14 additions & 0 deletions oop/classAutoBot.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions oop/classBaymax.js
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 10 additions & 0 deletions oop/classRobot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

class Robot {
constructor(name, purpose) {
this.name = name,
this.purpose = purpose
}
}

module.exports = Robot;
18 changes: 18 additions & 0 deletions oop/classRobotFactory.js
Original file line number Diff line number Diff line change
@@ -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<qty; i++){
if(type === 'wall-e') robots.push(new WallE());
if(type === 'baymax') robots.push(new BayMax());
if(type === 'autobot') robots.push(new AutoBot());
}
return robots;
}
}

module.exports = RobotFactory;
14 changes: 14 additions & 0 deletions oop/classWallE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'
const Robot = require('./classRobot');

class WallE extends Robot {
constructor() {
super('Wall-E', 'worker')
}

work() {
console.log(`Wall-E cleans the planet`)
}
}

module.exports = WallE;
18 changes: 18 additions & 0 deletions oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'
const RobotFactory = require('./classRobotFactory');

let wall_e = RobotFactory.produceRobot('wall-e', 6);
let baymax = RobotFactory.produceRobot('baymax', 5);
let autobot = RobotFactory.produceRobot('autobot', 3);

for (var i = 0; i < wall_e.length; i++) {
wall_e[i].work()
}

for (var i = 0; i < baymax.length; i++) {
baymax[i].heal();
}

for (var i = 0; i < autobot.length; i++) {
autobot[i].defend();
}
23 changes: 23 additions & 0 deletions query/Answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
1.
SELECT DISTINCT title, point, level, Players.name, age, gender
FROM Cards
LEFT JOIN Players
On Cards.playerid = Players.id
LEFT JOIN Status
On Cards.playerid = Status.playerid
ORDER BY level DESC;


2.
SELECT COUNT(*) AS totalcard, Players.id As playerId, Players.name, age, gender
FROM Cards
LEFT JOIN Players
On Cards.playerid = Players.id
WHERE gender = 'Male'
GROUP BY Players.name
ORDER BY totalcard DESC, Players.id
LIMIT 3;


*/