-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTHA7
More file actions
74 lines (56 loc) · 2.16 KB
/
THA7
File metadata and controls
74 lines (56 loc) · 2.16 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
THA DAY 7
1. Write a JavaScript program to list the properties of a JavaScript object. Sample object: var student = { name : "David Rayy", sclass : "VI", rollno : 12 };
CODE-
function _keys(obj)
{
if (!isObject(obj)) return [];
if (Object.keys) return Object.keys(obj);
var keys = [];
for (var key in obj) if (_.has(obj, key)) keys.push(key);
return keys;
}
2.Write a JavaScript program to delete the rollno property from the following object. Also print the object before or after deleting the property.
CODE-
var student = {
name : "David Rayy",
sclass : "VI",
rollno : 12 };
delete student.rollno;
console.log(student);
3. Write a JavaScript program to get the length of a JavaScript object. Sample object : var student = { name : "David Rayy", sclass : "VI", rollno : 12 };
CODE-
Object.objsize = function(Myobj) {
var size = 0, key;
for (key in Myobj) {
if (Myobj.hasOwnProperty(key)) size++;
}
return size;
};
4. Write a JavaScript program to display the reading status (i.e. display book name, author name and reading status) of the following books.
var library = [ { author: 'Bill Gates', title: 'The Road Ahead', readingStatus: true },
{ author: 'Steve Jobs', title: 'Walter Isaacson', readingStatus: true },
{ author: 'Suzanne Collins', title: 'Mockingjay: The Final Book of The Hunger Games', readingStatus: false }];
CODE-
for (var i = 0; i < library.length; i++)
{
if (library[i].readingStatus) {
console.log("read");
} else
{
console.log("not read");
}
}
5. Write a JavaScript program to get the volume of a Cylinder with four decimal places using object classes.
Volume of a cylinder : V = πr2h where r is the radius and h is the height of the cylinder.
CODE-
function Cylinder(cyl_height, cyl_diameter) {
this.cyl_height = cyl_height;
this.cyl_diameter = cyl_diameter;
}
Cylinder.prototype.Volume = function () {
var radius = this.cyl_diameter / 2;
return this.cyl_height * Math.PI * radius * radius;
};
var cyl = new Cylinder(7, 4);
console.log('volume =', cyl.Volume().toFixed(4));
6. Write a JavaScript program to sort an array of JavaScript objects.