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

livecode3 #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 43 additions & 10 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@ class RNG {

return result;
}

static gatchaRoll(times, callback) {
setTimeout(function () {
if(times === 0) {
callback(0)
} else {
for (let i = 0; i < times; i++) {
callback(RNG.roll());
}
}
}, 1000);
}

static gatchaRollPromise(times) {
return new Promise ( (resolve, reject) => {
if (times === 0) {
reject(err)
} else {
let arr = new Array()
for (let i = 0; i < times; i++) {
arr.push(RNG.roll());
}
resolve(arr.join(','))
}
})
}

}

function viewGachaResult(best) {
Expand All @@ -28,24 +55,30 @@ function viewGachaFailure() {
}

// 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
// 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
RNG.gatchaRollPromise(5)
.then(function(result) { viewGachaResult(result) })
.catch(function(err) { viewGachaFailure() };
// RNG.gatchaRollPromise(5)
// .then(function(result) { viewGachaResult(result) })
// .catch(function(err) { viewGachaFailure() });

// 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() };
// RNG.gatchaRollPromise(0)
// .then(function(result) { viewGachaResult(result) })
// .catch(function(err) { viewGachaFailure() })

// akan menampilkan di log: YAKIN NGGAK MAU NGE-ROLL?


// RELEASE 2 PROMISE(S)

// code here...
// code here...
Promise.all([RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1), RNG.gatchaRollPromise(1)])
.then(data => {
for (let i = 0; i < data.length; i++) {
viewGachaResult(data[i])
}
})
105 changes: 105 additions & 0 deletions oop/robot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
class Robot {
constructor(name, purpose) {
this.name = name
this.purpose = purpose
}

}

class WallE extends Robot {
constructor(name, purpose) {
super(name, purpose)
this.method = []
}

setWork(data) {
this.method.push(data)
}

get work() {
return 'Method WallE : ' + this.method[0]
}

}

class BayMax extends Robot {
constructor(name, purpose) {
super(name, purpose)
this.method = []
}

setHeal(data) {
this.method.push(data)
}

get heal() {
return 'Method BayMax : ' + this.method[0]
}
}

class AutoBot extends Robot {
constructor(name, purpose) {
super(name, purpose)
this.method = []
}

setDefend(data) {
this.method.push(data)
}

get defend() {
return 'Method AutoBot : ' + this.method[0]
}
}

class RobotFactory {
constructor() {}

static produceRobot(robot, num) {
let arrWalle = []

if (robot === 'wall-e') {

let walle = new WallE('Wall-E', 'worker')
walle.method.push('Wall-E cleans the planet')

for (let i = 0; i < num; i++) {
arrWalle.push(walle)
}

}
}

}

let wallRobot = new WallE('Wall-E', 'worker')
let bayMaxRobot = new BayMax('BayMax', 'medic')
let autoBotRobot = new AutoBot('AutoBot', 'defender')


wallRobot.setWork('Wall-E cleans the planet')
bayMaxRobot.setHeal('Hi, I am BayMax, how may I help you?')
autoBotRobot.setDefend("AutoBot, lets roll!")

// console.log(wallRobot)
// console.log(bayMaxRobot)
// console.log(autoBotRobot)


let wall_e = RobotFactory.produceRobot('wall-e', 6);
wall_e
// work()
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();
// }
Binary file modified query/database.db
Binary file not shown.
18 changes: 18 additions & 0 deletions query/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('database.db');

//Release 0
// db.all(`SELECT title, point, level, Players.name, age FROM Players
// INNER JOIN Status ON Status.playerId = Players.id GROUP BY name`, (err, row) => {
// if(err) throw err
// console.log(row)
// })

//Release 1
db.all(`SELECT (SELECT count(Cards.playerId) WHERE Cards.Id = Players.id) as totalCard ,Players.name, age, gender from Players
INNER JOIN Cards ON Cards.Id = Players.id WHERE gender = 'Male' GROUP BY Players.name ORDER BY totalCard LIMIT 3`, (err,row) => {
if (err) throw err
console.log(row)
})

db.close();