-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask3.js
More file actions
47 lines (38 loc) · 1.13 KB
/
Copy pathTask3.js
File metadata and controls
47 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//Tugas3
// buatlah 2 program bebas dengan menggunakan promise seperti soal nomor 1
// const number = (num1, num2) => {
// return new Promise((resolve, reject)=>{
// if(typeof num1 === "number" && typeof num2 === "number"){
// setTimeout(()=>{
// let result = num1 * num2
// resolve(result)
// }, 3000)
// }else{
// const error = "inputan harus number"
// reject(error)
// }
// })
// }
// number('a', 'b').then((res)=> {
// console.log(res)
// })
// .catch((err)=>{
// console.log(err)
// })
//tugas 2
const checkmyHobbies = (hobbi) => {
return new Promise((resolve, reject) => {
const myHobbies = ['makan', 'mancing', 'tidur', 'travelling', 'bermain']
let cek = myHobbies.filter((item) => {
return item === hobbi
})
if (cek) {
resolve(cek)
} else {
reject(new Error('Ini bukan hobbi saya'))
}
})
}
checkmyHobbies('makan')
.then((result) => console.log(result [0]))
.catch((error) => console.log(error))