-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
58 lines (46 loc) · 1.54 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
// //Q1 how to compare two JSON have the same properties without same order
// //a.letobj1={name:"Person1",age:5 };
// //b.letobj2={age:5 , name:"Person1"};
// let obj1 = {name: "Person1", age: 5};
// let obj2 = {age: 5, name: "Person1"};
// function isEqual(a, b)
// {
// const keysA = Object.keys(a).sort();
// const keysB = Object.keys(b).sort();
// if (JSON.stringify(keysA) !== JSON.stringify(keysB))
// return false;
// return keysA.every(key => a[key] === b[key]);
// }
// console.log(isEqual(obj1, obj2));
//Q2 Use te rest countries API url and display all the country flags in the console
// let request = new XMLHttpRequest();
// request.open("GET","https://restcountries.com/v3.1/all",true);
// request.send();
// request.onload = function()
// {
// let data = request.response;
// let result = JSON.parse(data);
// console.log(result);
// for(let i=0; i<result.length;i++)
// {
// console.log(result[i].flags.png);
// }
// }
// Q3 Using the same API Print countries name, region, sub-region & Population
var request3 = new XMLHttpRequest();
request3.open("GET", "https://restcountries.com/v3.1/all", true);
request3.send();
request3.onload = function () {
var data3 = request3.response;
//console.log(data3);
var result3 = JSON.parse(data3);
console.log(result3);
for (var i = 0; i < result3.length; i++) {
console.log(
"Country Name :" + result3[i].name.common,
"Region:" + result3[i].region,
"Subregion:" + result3[i].subregion,
"population:" + result3[i].population
);
}
};