-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
170 lines (147 loc) · 5.16 KB
/
script.js
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
//* 1. Write a constructor for the class Movie, which takes a String representing the title of the movie,
//* a String representing the studio, and a String representing the rating as its arguments, and sets
//* the respective class properties to these values.
class Movie {
constructor(title, studio, rating) {
this.title = title;
this.studio = studio;
this.rating = rating;
}
}
var mymovie = new Movie("Love Today", "AGS Entertainment", "PG-13");
console.log(mymovie);
//! OUTPUT
// title: 'Love Today', studio: 'AGS Entertainment', rating: 'PG-13'
//...................................................................................................
//* 2. The constructor for the class Movie will set the class property rating to "PG" as default when no rating is provided.
class Movie {
constructor(title, studio, rating) {
this.title = title;
this.studio = studio;
if(this.rating===undefined){
this.rating = "PG";
}else{
this.rating = rating;
}
}
}
var mymovie = new Movie("Love Today", "AGS Entertainment");
console.log(mymovie);
//! OUTPUT
//title: 'Love Today', studio: 'AGS Entertainment', rating: 'PG'
//..........................................
//* 3. Write a method getPG, which takes an array of base type Movie as its argument, and
//* returns a new array of only those movies in the input array with a rating of "PG".
//* You may assume the input array is full of Movie instances. The returned array need not be full.
class Movie {
constructor(title, studio, rating) {
this.title = title;
this.studio = studio;
if (this.rating === undefined) {
this.rating = "PG";
} else {
this.rating = rating;
}
getPG(array); {
var result = [];
for (var i = 0; i < array.length; i++) {
if (array[i].rating === "PG")
result.push(array[i]);
}
}
return result;
}
}
var moviel = new Movie("ABC", "MARVEL");
var movie2 = new Movie("gnh", "kk", "pg134"); var arr = [moviel, movie2, movie, movie4];
console.log(movie1.getPG(arr));
//...............................................................
//* 4. Write a piece of code that creates an instance of the class Movie with the title “Casino Royale”, the studio “Eon Productions”, and the rating “PG13”.
class Movie {
constructor(title, studio, rating) {
this.title = title;
this.studio = studio;
this.rating = rating;
}
}
var a =new Movie("Casino Royale","Eon productions","PG13");
console.log(a);
//! OUTPUT
// "title": "Casino Royale",
// "studio": "Eon productions",
// "rating": "PG13"
//......................................................................
//* 5. Circle.
class Circle {
constructor(radius, color) {
this.radius = radius;
this.color = color;
}
get radiusCircle() {
return this.radius;
}
get colorCircle() {
return this.color;
}
set radiusCircle(radius) {
this.radius = radius;
}
set colorCircle(color) {
this.color = color;
}
get toString() {
return `"Circle[radius=${this.radius}, color=${this.color}]"`;
}
get areaCircle() {
return Math.PI * this.radius * this.radius;
}
get circumferenceCircle() {
return 2 * Math.PI * this.radius;
}
}
var obj1 = new Circle(1.0, "red");
console.log(obj1.radiusCircle); //get radiusCircle
obj1.radiusCircle = 2.2;
console.log(obj1.radiusCircle); //set radiusCircle
//......................................................................
//* 6. write a "person" class to hold all the details?
class Person {
constructor(name,age,language,address,hobby,movies,programing_language_known){
this.name = name;
this.age = age;
this.language = language;
this.address = address;
this.hobby = hobby;
this.movies = movies;
}
}
var per =new Person("Jagatheesh","22","Tamil and English","YYYY","Reading comics","KGF and Love Today","Javascript");
console.log(per);
//!OUTPUT
//ddress: "YYYY"
// age: "22"
// hobby: "Reading comics"
// language: "Tamil and English"
// movies: "KGF and Love Today"
// name: "Santhosh"
//.............................................................
//* 7. write a class to calculate the uber price
class Uber{
constructor(city1,city2,city3){
this.city1 = city1;
this.city2 = city2;
this.city3 = city3;
}
}
var price = new Uber(20,30,50);
console.log("Rs."+price.city1+" for 5 kilometers");
console.log("Rs."+price.city2+" for 10 kilometers");
console.log("Rs."+price.city3+" for 15 kilometers");
var total = new Uber(20+30+50);
console.log("Rs."+total.city1+" for all the cities");
//!OUTPUT
// 20 for 5 kilometers
// 142 30 for 10 kilometers
// 143 50 for 15 kilometers
// script.js:145 100 for all the cities
//................................................................