-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (65 loc) · 2.24 KB
/
script.js
File metadata and controls
73 lines (65 loc) · 2.24 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
//* Get all the countries from the Asia continent /region using the Filter function
var a = new XMLHttpRequest();
a.open("GET","https://restcountries.com/v3.1/all");
a.send();
a.onload = function(){
var data = a.response
var result = JSON.parse(data);
var res = result.filter((ele)=>{
if(ele.region==="Asia")
return ele.name;
});
console.log(res);
}
//.....................................................
// * Get all the countries with a population of less than 2 lakhs using Filter function
var a = new XMLHttpRequest();
a.open("GET","https://restcountries.com/v3.1/all");
a.send();
a.onload = function(){
var data = a.response
var result = JSON.parse(data);
var res1 = result.filter((ele)=>ele.population<200000)
var res2 = res1.map((ele)=>`${ele.population}:${ele.name.common}`)
console.log(res2)
}
//................................................................
//* Print the following details name, capital, flag using forEach function
var a = new XMLHttpRequest();
a.open("GET","https://restcountries.com/v3.1/all");
a.send();
a.onload = function(){
var data = a.response
var result = JSON.parse(data);
result.forEach(element => {
console.log(element.name.common+" "+element.capital+" "+element.flags.png)
});
}
//......................................................................................
//* Print the total population of countries using reduce function
var a = new XMLHttpRequest();
a.open("GET","https://restcountries.com/v3.1/all");
a.send();
a.onload = function(){
var data = a.response
var result = JSON.parse(data);
var res = result.reduce((acc,cv)=>acc+cv.population,0)
console.log(res)
}
//...................................................................................
//* Print the country which uses US Dollars as currency.
var a = new XMLHttpRequest();
a.open("GET","https://restcountries.com/v2/all");
a.send();
a.onload = function(){
var data = a.response
var result = JSON.parse(data);
var res = result.filter((ele)=>{
for(let key in ele.currencies){
if(ele.currencies[key].code==="USD"){
console.log(ele.name)
}
}
})
}
//....................................................................................