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

Agnynureza #25

Open
wants to merge 3 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
67 changes: 56 additions & 11 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,46 @@ class RNG {

return result;
}
static gatchaRoll(times,callback){
let max = []
if(times > 0){
for(let i = 0 ; i < times ; i++){
let gacha = RNG.roll()
max.push(gacha)
console.log(`go gacha: ${gacha}`)
}
max.sort(function(a,b){return b > a})
setTimeout(function(){
callback(max[0])
},1000)
}else{
setTimeout(function(){
callback(0)
},1000)
}
}

static gatchaRollPromise(times,callback){
return new Promise((resolve,reject)=>{
if(times > 0 ){
let max = []
for(let i = 0 ; i < times ; i++){
let gacha = RNG.roll()
max.push(gacha)
console.log(`gacha promise: ${gacha}`)
}
max.sort(function(a,b){return b > a})
setTimeout(function(){
resolve(max[0])
},1000)
}else{
reject()
}
})
}



}

function viewGachaResult(best) {
Expand All @@ -27,25 +67,30 @@ function viewGachaFailure() {
console.log('YAKIN NGGAK MAU NGE-ROLL?');
}


// 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...
RNG.gatchaRollPromise(5).then(result => viewGachaResult(result))
RNG.gatchaRollPromise(4).then(result => viewGachaResult(result))
RNG.gatchaRollPromise(3).then(result => viewGachaResult(result))
RNG.gatchaRollPromise(2).then(result => viewGachaResult(result))
RNG.gatchaRollPromise(1).then(result => viewGachaResult(result))
.catch(function(err) { viewGachaFailure() });
67 changes: 67 additions & 0 deletions oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

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(robot,amount){
let factory = []
for(let i = 0 ; i < amount ; i ++){
if(robot === 'wall-e'){
factory.push(new WallE)
}else if(robot === 'baymax'){
factory.push(new Baymax)
}else{
factory.push(new AutoBot)
}
}
return factory
}
}

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();
}
Binary file modified query/database.db
Binary file not shown.
30 changes: 30 additions & 0 deletions query/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('database.db');

function release0(){
db.all(`select status.title,status.point,status.level,players.name,players.age,players.gender
from status join players on status.playerid = players.id
group by players.id order by status.level desc`,function(err,data){
if(err){
throw err
}else{
console.log(data)
}
})
}

function release1(){
db.all(`select count(cards.playerid)as totalcard,players.id,players.name,players.age,players.gender
from cards join players on cards.playerid = players.id where players.gender = 'Male'
group by cards.playerid order by totalcard desc limit 3 `,function(err,data){
if(err){
throw err
}else{
console.log(data)
}
})

}

release0()
release1()