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

Release 0: Belanja -- Haidar #5

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
7 changes: 5 additions & 2 deletions beli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ function beli(uang, obj, cb){
let kembalian = uang - obj.harga
if (kembalian > 0) {
console.log(`Saya sudah membeli ${obj.item} uang kembaliannya ${kembalian}`);
cb(kembalian)
cb(kembalian).then((data) => {
console.log(data);
})
return true;
}else{
console.log(`uang gk cukup nih buat beli ${obj.item} kembaliannya cuma ${kembalian}`);
cb(0)
return false;
}
}, obj.waktu);
}
Expand Down
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const beli = require('./beli');
const belanjaan = {
item: 'baju',
harga: 1000,
waktu: 1000
};

const belanja = (uangBelanja) => {
const promise = new Promise((resolve, reject) => {
if (uangBelanja <= 0) {
reject('Belanja Selesai, Uang Sudah Habis');
} else {
let doBeli = beli(uangBelanja,belanjaan,belanja);
resolve('Lanjut Belanja');
}
})
return promise;
}

belanja(6000).then((data) => {
console.log(data);
})
.catch((err) => {
console.log(err);
})