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 #24

Open
wants to merge 1 commit 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: 51 additions & 2 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,47 @@ class RNG {

return result;
}

static gatchaRoll(times, callback) {
setTimeout(function() {
let result = 0;
let currentResult = 0;
while(times > 0) {
// console.log(RNG.roll(),'<<<<')
currentResult = RNG.roll()
if(currentResult > result) {
result = currentResult
}
times--
}
callback(result)
}, 1000)
}

static gatchaRollPromise(times) {
return new Promise((resolve,reject)=>{
setTimeout(()=>{
let result = 0;
let currentResult = 0;
while(times > 0) {
// console.log(RNG.roll(),'<<<<')
currentResult = RNG.roll()
if(currentResult > result) {
result = currentResult
}
times--
}
if(result > 0){
resolve(result)
} else {
reject(0)
}
}, 1000)
})
}
}


function viewGachaResult(best) {
console.log(`YOUR BEST GATCHA ROLL RESULT IS ${best}`);
}
Expand All @@ -35,17 +74,27 @@ 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() };
.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() };
.catch(function(err) { viewGachaFailure() });

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


// RELEASE 2 PROMISE(S)

RNG.gatchaRollPromise(5)
.then(function(result) { gatchaRollPromise(result)
.then(function(result){ gatchaRollPromise(result)
.then(function(result){ gatchaRollPromise(result)
.then(function(result){ viewGachaResult(result)})
.catch(function(err){ viewGachaFailure() })})
.catch(function(err){ viewGachaFailure()})})
.catch(function(err) { viewGachaFailure() }) })
.catch(function(err) { viewGachaFailure() });

// code here...
70 changes: 70 additions & 0 deletions oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class Robot {
constructor(name, purpose) {
this.name = name
this.purpose = purpose
}
}

class WallE extends Robot {
constructor(name, purpose) {
super(name, purpose)
}

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

class BayMax extends Robot {
constructor(name, purpose) {
super(name, purpose)
}

heal() {
console.log(`Hi, I am BayMax, how may I help you?`)
}
}

class AutoBot extends Robot {
constructor(name, purpose) {
super(name, purpose)
}

defend() {
console.log(`AutoBot, let's roll!`)
}
}

class RobotFactory {
static produceRobot(name, count) {
let robot = []
while(count > 0) {
if(name === 'wall-e') {
robot.push(new WallE('Wall-E', 'worker'))
} else if(name === 'baymax') {
robot.push(new BayMax('BayMax', 'medic'))
} else if(name === 'autobot') {
robot.push(new AutoBot('AutoBot', 'defender'))
}
count--
}
return robot
}
}
//------------------------------------------------
let wall_e = RobotFactory.produceRobot('wall-e', 6);
let baymax = RobotFactory.produceRobot('baymax', 5);
let autobot = RobotFactory.produceRobot('autobot', 3);
// console.log(wall_e)
// console.log(baymax[0].heal())
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();
}
11 changes: 11 additions & 0 deletions query/query.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## RELEASE 0
SELECT Status.title, Status.point, Status.level,
Players.name, Players.age, Players.gender FROM Status
JOIN Players ON Status.playerId = Players.id
ORDER BY level DESC;

## RELEASE 1
SELECT COUNT(*) as totalCards, Cards.playerId,
Players.name, Players.age, Players.gender FROM Cards
JOIN Players ON Cards.playerId = Players.id
GROUP BY Players.name ORDER BY totalCards DESC LIMIT 3