-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample2.js
More file actions
125 lines (95 loc) · 2.26 KB
/
sample2.js
File metadata and controls
125 lines (95 loc) · 2.26 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// constructor
class home{
constructor (area,Budget,plan){
this.area=area;
this.Budget=Budget;
this.plan=plan;
}
memory(){
console.log(`I want my house at ${this.area} \n Looking for a reasonable ${this.Budget} \n In a neat scope of ${this.plan}`);
}
}
const dinglo = new home("Anna Nagar", "50 Lakhs", "Freak style")
dinglo.memory();
// constructor method
class laptop{
constructor(brand, speed, price){
this.brand=brand;
this.speed=speed;
this.price=price
}
income(){
console.log(`I want a ${this.brand}\n I need a ${this.speed}\n clock speed ${this.price}`)
}
}
let overall = new laptop ("Lenova", "8 Gb", "20 thousand")
overall.income()
// call back function
function party (callback) {
setTimeout(() =>{
console.log("ready for party");
callback()
},2000)
}
function Newyear(callback){
setTimeout(() => {
console.log("ringa ringa new year");
},500)
}
party(Newyear);
let a = (" I love my country")
console.log(a.split);
// promise
//wedding , dress, shop, money
function wedding (){
return new Promise ((resolve,reject)=>{
setTimeout (()=>{
const attend = true
if(attend){
resolve("Sure will attend wedding")
}
else{
reject("will not attend wedding")
}
}, 4000);
})
}
function shopping (){
return new Promise ((resolve,reject)=>{
setTimeout(() => {
const dress = true
if (dress){
resolve("Going to take dress")
}
else{
reject("Not going to take dress")
}
}, 3000)
})
}
function gift(){
return new Promise ((resolve,reject)=>{
setTimeout (()=>{
const gold = false
if (gold){
resolve("Going to buy")
}
else{
reject("Not going to buy")
}
}, 2000);
})
}
async function familywedding (){
try{
let dance = await wedding ()
console.log(dance);
let drink = await shopping ()
console.log(drink);
let maas = await gift ()
console.log(maas);
} catch (booze){
console.log(booze);
}
}
familywedding()