-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
38 lines (31 loc) · 1.2 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
/*1.How to compare two JSON have the same properties without order?
a.let obj1={name:"Person 1",age:5};
b.ler obj2={age:5,name:"Person 1"};*/
const obj1 = {name:"Person 1", age:5};
const obj2 = {age:5, name:"Person 1"};
const obj1Keys = Object.keys(obj1);
const obj2Keys = Object.keys(obj2);
if (obj1Keys.length !== obj2Keys.length) {
console.log('Objects have different properties');
} else {
console.log('Objects have same properties');
}
//output:Objects have same properties
/*2.Use the rest countries API URL->https://restcountries.com/v3.1/all and display all the country
flags in the console*/
var request= new XMLHttpRequest();
request.open("GEt","https://restcountries.com/v3.1/all");
request.send();
request.onload = function() {
var result = JSON.parse(request.response);
for (var i = 0; i < result.length; i++) {
console.log(result[i].flags);
}
/*3.Use the same rest countries and print all countries names, region, sub-region and population*/
for (var i = 0; i < result.length; i++) {
console.log("Name:"+result[i].name );
console.log("Region:"+ result[i].region);
console.log("sub-region:"+ result[i].subregion);
console.log("population:"+result[i].population);
}
}