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

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

return result;
}
static gatchaRoll(times, callback){
let arr =[];
for(let i=0; i<times; i++){
let result = RNG.roll();
arr.push(result);
}
let highest = Math.max(...arr);
if(highest === -Infinity)highest =0;
setTimeout(function() {
// jalankan sesuatu disini setelah 1 detik
callback(highest);
}, 1000);
}
static gatchaRollPromise(times){
return new Promise ((resolve,reject)=>{
let arr=[];
for(let i=0; i<times; i++){
let result = RNG.roll();
arr.push(result);
}
let highest = Math.max(...arr);
if(highest === -Infinity){
highest = 0;
setTimeout(function() {

reject(highest);
}, 1000);
} else {
setTimeout(function() {
resolve(highest);
}, 1000);
}
})
}
}

function viewGachaResult(best) {
Expand All @@ -28,24 +62,55 @@ 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() });

// RELEASE 1 TEST CASES
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>

// 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?

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

// // RELEASE 2 PROMISE(S)

// RELEASE 2 PROMISE(S)
// // code here...
let promise1 = RNG.gatchaRollPromise(5);
let promise2 = RNG.gatchaRollPromise(5);
let promise3 = RNG.gatchaRollPromise(5);
let promise4 = RNG.gatchaRollPromise(5);
let promise5 = RNG.gatchaRollPromise(5);
let promise6 = RNG.gatchaRollPromise(5);
let promise7 = RNG.gatchaRollPromise(5);
let promise8 = RNG.gatchaRollPromise(5);
let promise9 = RNG.gatchaRollPromise(5);
let promise10 = RNG.gatchaRollPromise(5);

// code here...
Promise.all([
promise1,
promise2,
promise3,
promise4,
promise5,
promise6,
promise7,
promise8,
promise9,
promise10,
]).then(function(values) {
for(let i=0; i<values.length; i++){
if(values[i]===0){
viewGachaFailure();
} else {
viewGachaResult(values[i]);
}
}
})
66 changes: 66 additions & 0 deletions oop/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Robot {
constructor(name,purpose){
this.name = name;
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!`);
}
}
// let wall_e = new WallE;
// let baymax = new BayMax;
// let autobot = new AutoBot;
wall_e.work();
baymax.heal();
autobot.defend();
// console.log(WallE.work());
// console.log(BayMax.heal());
// console.log(AutoBot.defend());

// class RobotFactory {
// static produceRobot(name,amount){
// }
// }

// 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/main.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');

class Query {
static show(){
let query =`select Status.title, Status.point, Status.level, Players.name,Players.age,Players.gender
from Status
join Players
on Status.playerId = Players.id
order by 3 desc; `
db.all(query,(err,rows)=>console.log(rows));
}
static show2(){
let query =`select count(Cards.playerId) as totalcard, Players.id as playerI, Players.name, Players.age,Players.gender
from Cards
join Players
on Cards.playerId = Players.id
where Players.gender like "male%"
group by 2
order by 1 desc
limit 3`
db.all(query,(err,rows)=>console.log(rows));
}
}

Query.show();
Query.show2();