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

livecode 3 #16

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
50 changes: 46 additions & 4 deletions async/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,48 @@ class RNG {

return result;
}
static gatchaRoll(times, callback){
setTimeout(function() {
let result = []
if (times === 0 ){
callback(0)
}else{
for(let i =0; i<times; i++){
result.push(RNG.roll())
}
result.sort(function(a, b) {
return b- a;
});
callback(result[0]);
}
}, 1000);
}
static gatchaRollPromise(times){
return new Promise(function(resolve, reject) {
setTimeout(function() {
let result = []
if (times === 0 ){
reject(err=>console.log(err))
}else{
for(let i =0; i<times; i++){
result.push(RNG.roll())
}
result.sort(function(a, b) {
return b - a;
});
resolve(result[0]);
}
}, 1000);
})
}

static getRollTen(times){
return new Promise(function(resolve, reject) {
setTimeout(function() {
}, 1000);
})
}

}

function viewGachaResult(best) {
Expand All @@ -32,16 +74,16 @@ RNG.gatchaRoll(5, function(result) { viewGachaResult(result) }); // output log s
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?

Expand Down
17 changes: 17 additions & 0 deletions oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const RobotFactory = require('./robotfactory')

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();
}
44 changes: 44 additions & 0 deletions oop/robot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Robot{
constructor (){
this.name = 'Robot'
this.purpose = 'purpose'
}
}

class WallE extends Robot{
constructor(){
super()
this.name= 'Wall-E'
this.purpose= 'worker'
}
work(){
console.log('Wall-E cleans the planet')
}
}

class BayMax extends Robot{
constructor(){
super()
this.name= 'BayMax'
this.purpose= 'medic'
}
heal(){
console.log('Hi, I am BayMax, how may I help you?')
}
}
class AutoBot extends Robot{
constructor(){
super()
this.name = 'AutoBot'
this.purpose= 'defender'
}
defend(){
console.log("AutoBot, let's roll!")
}
}

module.exports = {
WallE,
BayMax,
AutoBot
}
22 changes: 22 additions & 0 deletions oop/robotfactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const {WallE,BayMax,AutoBot} = require('./robot')

class RobotFactory{
static produceRobot(robot, length){
let arr = []
for(let i =0; i<length; i++){
if(robot ==='wall-e'){
let wallE = new WallE()
arr.push(wallE)
}else if(robot === 'baymax'){
let bayMax = new BayMax()
arr.push(bayMax)
}else{
let autoBot = new AutoBot()
arr.push(autoBot)
}
}
return arr
}
}

module.exports = RobotFactory
Binary file modified query/database.db
Binary file not shown.
26 changes: 26 additions & 0 deletions query/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('database.db');

db.serialize(function() {
let query = `SELECT title, point, level, name, age, gender FROM Players
INNER JOIN Status on Players.id = Status. playerId
ORDER BY Status.level DESC`
db.all(query,(err,rows)=>{
if (err) throw err;
//console.log(rows)
})

let query2 = `SELECT count(Cards.playerId) as totalCard, playerId, Players.name, age, gender FROM Players
INNER JOIN Cards on Players.id = Cards.playerId
GROUP BY playerId
HAVING Players.gender = 'Male'
ORDER BY totalCard DESC
LIMIT 3`
db.all(query2,(err,rows)=>{
if (err) throw err;
console.log(rows)
})
})

// tampilkan `player` yang memiliki `jumlah kartu`, dan berjenis kelamin `male`
// serta tampilkan 3 teratas dari yang paling banyak jumlah kartunya.
2 changes: 1 addition & 1 deletion query/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "query",
"version": "1.0.0",
"description": "",
"description": "### dilarang menggunakan view, sub-query",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down