-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.js
More file actions
224 lines (195 loc) Β· 4.99 KB
/
object.js
File metadata and controls
224 lines (195 loc) Β· 4.99 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/**
* -------------------------- OBJECT IN JAVASCRIPT ---------------------------
*/
// ----------------------------------------------------------------------------
/**
* TEST : My data object exporting
*/
let myData = {
name: "Ninja",
role: "Developer",
age: 20,
};
export default { myData };
// ----------------------------------------------------------------------------
/**
* TEST : Create an object.
*/
// function About (name, age, role, state){
// this.name = name;
// this.age = age;
// this.role = role;
// this.state = state;
// this.data = ()=>{
// console.log(`Hi, I am ${this.name} and I am a ${this.age} years old ${this.role}. and I am based on ${this.state}.`)
// }
// }
// const Vikash = new About("Vikash Kumar", 20, "Developer", "Jharkhand")
// Vikash.data()
// const Sneha = new About("Sneha Sharma", 17, "Student", "Jammu")
// Sneha.data()
// ----------------------------------------------------------------------------
/**
* TEST : Add new values and Update values in the existing object at once.
*/
// let StudentData = {
// name : "Vikash",
// role : "Web Developer",
// age : 20,
// state : "JH",
// status : "Married"
// }
// let newData = {
// country : "INDIA",
// contact : 1234567890,
// email : "[email protected]"
// }
// let update = {
// name : "Vikash Kumar",
// status : "Single"
// }
// StudentData = {...StudentData, ...newData, ...update}
// console.log(StudentData)
// ----------------------------------------------------------------------------
/**
* TEST : Common array operations with an array of objects
*/
// let Pokemon = [
// {
// butterfree: {
// leg: 2,
// type: "bug",
// },
// },
// {
// bulbasaur: {
// leg: 4,
// type: "grass",
// },
// },
// {
// charmendar: {
// leg: 2,
// type: "fire",
// },
// },
// {
// squirtle: {
// leg: 2,
// type: "water",
// },
// },
// ];
// Pokemon.push({
// pikachu: {
// leg: 2,
// type: "electric",
// },
// });
// Pokemon.pop()
// console.log(Pokemon);
// ----------------------------------------------------------------------------
/**
* TEST : For finding all the available types in PokeDex
*/
// let Pokedex = [
// {
// butterfree: {
// leg: 2,
// type: "bug",
// },
// },
// {
// bulbasaur: {
// leg: 4,
// type: "grass",
// },
// },
// {
// charmendar: {
// leg: 2,
// type: "fire",
// },
// },
// {
// squirtle: {
// leg: 2,
// type: "water",
// },
// },
// ];
// for (const key in Pokedex) {
// const pokemon = Pokedex[key];
// for (const key in pokemon) {
// const e = pokemon[key];
// console.log(e.type);
// }
// }
// ----------------------------------------------------------------------------
/**
* TEST : Create an object for student marks entry and get total marks, grade
*/
function studentEntry(...marks) {
let MARK = [];
MARK.push(...marks);
this.result = function () {
if (MARK.length > 5 || MARK.length < 5) {
console.log("PLEASE CHECK YOUR INPUT MARKS MAY BE YOU HAVE ENTERED MORE OR LESS INPUTS");
} else {
let total = MARK.reduce((a, b) => a + b);
let grade = total / 5;
if (grade >= 0 && grade < 33) {
console.log(`YOUR SCORE IS : ${total} AND GRADE : F`);
} else if (grade >= 33 && grade < 45) {
console.log(`YOUR SCORE IS : ${total} AND GRADE : D`);
} else if (grade >= 45 && grade < 55) {
console.log(`YOUR SCORE IS : ${total} AND GRADE : C`);
} else if (grade >= 55 && grade < 65) {
console.log(`YOUR SCORE IS : ${total} AND GRADE : B`);
} else if (grade >= 65 && grade < 75) {
console.log(`YOUR SCORE IS : ${total} AND GRADE : A`);
} else {
console.log(`YOUR SCORE IS : ${total} AND GRADE : A+`);
}
}
};
}
let Ajay = new studentEntry(30, 30, 30, 30);
// Ajay.result()
let Rohit = new studentEntry(67, 56, 78, 56, 77);
Rohit.result()
let Sanjay = new studentEntry(90, 79, 56, 45, 44, 56);
// Sanjay.result()
// ----------------------------------------------------------------------------
/**
* TEST : Course Constructor & Data Viewer
*/
function Course(...arg){
this.title = arg[0];
this.price = arg[1];
this.duration = arg[2];
this.author = "Ninja-Vikash"
}
// ------> Create your course here
let DSA = new Course("DSA", 1999, 4);
let JAVASCRIPT = new Course("JavaScript", 1499, 6);
let HTML = new Course("HTML", 799, 5);
let CSS = new Course("CSS", 899, 3);
let REACT = new Course("React", 1999, 8);
let NODEJS = new Course("Node.js", 1799, 9);
/**
* Pass values as Course(_course_name, _price, _duration)
*/
function dataViewer(courseName){
console.log("---COURSE DETAILS---")
for (const key in courseName) {
const value = courseName[key];
console.log(`${key} : ${value}`)
}
console.log("---COURSE DETAILS---")
}
// ------> Get Your course details
// dataViewer(DSA)
// dataViewer(REACT)
dataViewer(NODEJS)
// dataViewer(CSS)