-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task (004).txt
298 lines (223 loc) · 8.16 KB
/
Task (004).txt
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
//Submitted by Jagadeesh Kumar . S
1. How to compare two JSON have the same properties without order?
a. var obj1 = { name: "Person 1", age:5 };
b. var obj2 = { age:5, name: "Person 1"};
=>Answer.
var obj1 = { name: "Person 1", age:5 };
var obj2 = { age :5 , name:"Person 1"};
//fetch properties
let prop1 = Object.getOwnPropertyNames(obj1);
let prop2 = Object.getOwnPropertyNames(obj2);
//will loop in for loop, iterating the list of properties and then comparing their values
for (let i = 0; i <obj1.length; i++) {
let obj = obj1[i];
if (obj1[prop] !== obj2[prop]) {
console.log("false");
}
}
console.log("true");
2. Use the rest countries' API URL ->http://restcountries.rest/v3/all and display all the country flags in the console.
=>Answer.
var request=new XMLHttpRequest();
request.open('GET','https://restcountries.com/v3.1/all',true)
request.send();
request.onload=function() {
var data=JSON.parse(this.response)
console.log(data)
console.log(data[0].flag)
console.log(data[0].flags.png)
console.log(data[0].flags.svg)
// for loop
for(i=0;i<data.length;i++){
console.log(data[i].flag)
console.log(data[i].flags.png)
console.log(data[i].flags.svg)
}
}
3. Use the same rest countries and print all countries name, region, sub region and population
var request=new XMLHttpRequest();
request.open('GET','https://restcountries.com/v3.1/all',true)
request.send();
request.onload=function() {
var data=JSON.parse(this.response)
console.log(data)
console.log(data[0].name)
console.log(data[0].name.common)
console.log(data[0].capital)
console.log(data[0].region)
console.log(data[0].subregion)
console.log(data[0].population)
// for loop
for(i=0;i<data.length;i++) {
console.log(data[i].name.common)
console.log(data[i].capital)
console.log(data[i].region)
console.log(data[i].subregion)
console.log(data[i].population)
}
}
4. https://medium.com/@reach2arunprakash/www-guvi-io-zen-d395deec1373
=>Answer.
// //1. Declare four variables without assigning values and print them in console
// let x,y,z,a
// console.log(x,y,z,a);
// //2. value of the variable myvar as output
// var myvar= 1;
// console.log(myvar);
// //3.Declare variables to store your first name, last name, marital status, country and age in multiple lines
// let firstName = "Soumya";
// let lastName = "Dutta";
// let maritialStatus = "Unmmarried";
// let country = "India";
// let age = 29 ;
// console.log(firstName);
// console.log(lastName);
// console.log(maritialStatus);
// console.log(country);
// console.log(age);
// //4.Declare variables to store your first name, last name, marital status, country and age in a single line
// console.log(firstName, lastName, maritialStatus, country, age);
// //5. Declare variables and assign string, boolean, undefined and null data types
// let str = "Soumya";
// let bool = true;
// let unde;
// let nul = null;
// //6. Convert the string to integer parseInt() Number() Plus sign(+)
// let str1 = "1234";
// let convstr1 = parseInt(str1);
// console.log(typeof(str1));
// //7. Write 6 statement which provide truthy & falsey values.
// //truthy statements
// if(true) {
// x= 45;
// }
// if (3===3) {
// x = 34;
// }
// if (34) {
// x = 24;
// }
// //falsy statements
// if (false) {
// x = 23;
// }
// if (0) {
// x=56;
// }
// if (null) {
// x=9;
// }
// //Task 2: Simple Programs todo for Operators
// //1. Square of a number
// let num1 = 3;
// console.log(`Square of ${num1} is ${num1*num1}`);
// //2. Swapping 2 numbers
// let num2 = 3;
// let num3 = 4;
// let f = num2;
// num2=num3;
// num3 = f;
// console.log(`Swapped numbers are num2 ie. ${num2} and num3 ie. ${num3}`);
// //3. Addition of 3 numbers
// let x = 3;
// let y = 4;
// let z = 5;
// console.log(`Addition of 3 numbers x,y and z is ${x+y}`)
// //4. Celsius to fahrenheit conversion
// let tcel = 24;
// console.log(`${tcel} deg celsius is ${tcel*9/5 + 32} in Fahrenheit`);
// //5. Meter to miles
// let m = 2000;
// console.log(`The distance ${m} meter in miles is ${m/1609.344}`);
// //6.Pounds to kg
// let massInPounds = 75;
// console.log(`${massInPounds} pounds is ${0.45359237*massInPounds} in kg`);
// //7.Calculate Batting Average
// let totalRuns = 23000;
// let totalOuts = 350;
// console.log(`Batting Average of the player is ${totalRuns/totalOuts}`);
// //8. Calculate five test scores and print their average
// let totalScore = 442;
// let totalTest = 5;
// console.log(`Average Test Score Secured = ${totalScore/totalTest}`);
// //9.Power of any number x ^ y
// let num4 = 4;
// let power = 2;
// console.log(`Power of the given number ${num4} is ${Math.pow(num4,power)}.`);
// //10.Calculate Simple Interest
// let principal = 20000;
// let timePeriod = 2;
// let interestRate = 5;
// console.log(`The simple interest on the principle amount is Rs.${principal*timePeriod*interestRate/100}`);
// //11.Calculate area of an equilateral triangle
// let side = 5;
// console.log(`Area of equilateral triangle with side ${side}cm is ${Math.sqrt(3)/4 * Math.pow(side,2)}`);
// //12. Area Of Isosceles Triangle
// let base = 20;
// let height = 10;
// console.log(`Area of isosceles triangle with base ${base}cm and height ${height}cm is ${base*height/2} square cm. `);
// //13. Volume of Sphere
// let radius = 5;
// console.log(`Volume of Sphere with radius ${radius}cm is ${4/3 * 3.141 * Math.pow(radius,3)}`);
// //14. Volume of Prism
// let baseLength = 10;
// let basewidth = 30;
// let prismHeight = 15;
// console.log(`Volume of Prism is ${baseLength*basewidth*prismHeight/2}.`);
// //20. a consumer consumes 100 watts per hour daily for one month. Calculate the total energy bill of that consumer if per unit rate is 10?
// let perUnitRate = 10;
// let unitConsumedPerHour = 100;
// let totalUnit = unitConsumedPerHour*24*30;
// console.log(`Total Energy Bill is ${totalUnit*perUnitRate}.`);
// TASK-3 Simple Programs todo for Condition , Looping and Arrays
// 1. Write a loop that makes seven calls to console.log to output the following triangle:
// #
// ##
// ###
// ####
// #####
// ######
// #######
// let string = "";
// let n = 6;
// for (let x=0 ; x<=n ; x++) {
// for(let y=0 ; y<=x ; y++) {
// string+="#";
// }
// string+="\n";
// }
// console.log(string);
//2. Iterate through the string array and print it contents
// var strArray= ["<option>Jazz</option>",
// ,"<option>Blues</option>",
// ,"<option>New Age</option>",
// ,"<option>Classical</option>",
// ,"<option>Opera</option>"];
// for(let values of strArray) {
// console.log(values);
// }
//write a code to count the elements in the array . Don’t use length property
// var myarray=[11,22,33,44,55];
// let n = 0;
// for (let values of myarray) {
// n+=1;
// }
// console.log(`The no. of elements in the array is ${n}`);
// let foods = ["egg", "paneer", "chicken", "mutton", "mushroom", "soyabean", "lamb", "duck", "beans", "spinach", "beef", "pizza", "burger", "pasta",
// "noodles", "mixture","lasagna","rice","roti","paratha"];
// // Foods variable holds the names of your top 20 favorite foods, starting with the best food. How can you find your fifth favorite food?
// console.log(`My fifth favorite food is ${foods[4]}`);
// // Find the length of your foods array
// console.log (`The length of my foods array is ${foods.length}`)
// Starting from the existing friends variable below, change the element that is currently “Mari” to “Munnabai”.
// let friends = [ "Mari","MarryJane","CaptainAmerica","Munnabai","Jeff","AAK chandran"];
// function dataHandling(input){
// for (let i = 0; i < input.length; i++) {
// if (input[i] === "Mari") {
// input[i] = "Munnabai";
// }
// }
// console.log(input);
// }
// dataHandling(friends);
//Submitted by Jagadeesh Kumar . S