|
1 |
| -// //Q1 |
2 |
| -// // Get all the countries from Asia continent /region using Filter function |
| 1 | +//Q1 |
| 2 | +// Get all the countries from Asia continent /region using Filter function |
3 | 3 |
|
4 |
| -// var xml=new XMLHttpRequest(); |
5 |
| -// xml.open("GET","https://restcountries.com/v3.1/all"); |
6 |
| -// xml.send(); |
7 |
| -// xml.onload=function(){ |
8 |
| -// var data=xml.response; |
9 |
| -// var res=JSON.parse(data) |
10 |
| -// console.log("------------------------!Starting 1st one!--------------------"); |
11 |
| -// var continent=res.filter((val)=>val.continents=="Asia") |
12 |
| -// var continentres=continent.map((country)=>console.log(country.name.common)) |
| 4 | +var xml=new XMLHttpRequest(); |
| 5 | +xml.open("GET","https://restcountries.com/v3.1/all"); |
| 6 | +xml.send(); |
| 7 | +xml.onload=function(){ |
| 8 | + var data=xml.response; |
| 9 | + var res=JSON.parse(data) |
| 10 | + console.log("------------------------!Starting 1st one!--------------------"); |
| 11 | + var continent=res.filter((val)=>val.continents=="Asia") |
| 12 | + var continentres=continent.map((country)=>console.log(country.name.common)) |
13 | 13 |
|
14 | 14 |
|
15 |
| -// } |
| 15 | +} |
16 | 16 |
|
17 |
| -// // Q2 |
18 |
| -// // Get all the countries with a population of less than 2 lakhs using Filter function |
| 17 | +// Q2 |
| 18 | +// Get all the countries with a population of less than 2 lakhs using Filter function |
19 | 19 |
|
20 |
| -// var xml2=new XMLHttpRequest(); |
21 |
| -// xml2.open("GET","https://restcountries.com/v3.1/all"); |
22 |
| -// xml2.send(); |
23 |
| -// xml2.onload=function(){ |
24 |
| -// console.log("------------------------!Finished 1st one!--------------------"); |
25 |
| -// console.log("------------------------!Starting 2nd !--------------------"); |
26 |
| -// var data=xml2.response; |
27 |
| -// var res=JSON.parse(data); |
| 20 | +var xml2=new XMLHttpRequest(); |
| 21 | +xml2.open("GET","https://restcountries.com/v3.1/all"); |
| 22 | +xml2.send(); |
| 23 | +xml2.onload=function(){ |
| 24 | + console.log("------------------------!Finished 1st one!--------------------"); |
| 25 | + console.log("------------------------!Starting 2nd !--------------------"); |
| 26 | + var data=xml2.response; |
| 27 | + var res=JSON.parse(data); |
28 | 28 |
|
29 | 29 |
|
30 |
| -// var population=res.filter((val)=>val.population<200000) |
| 30 | + var population=res.filter((val)=>val.population<200000) |
31 | 31 |
|
32 |
| -// var populationres=population.map((val)=>console.log(val.name.common)) |
| 32 | + var populationres=population.map((val)=>console.log(val.name.common)) |
33 | 33 |
|
34 |
| -// } |
35 |
| -// //Q3 |
36 |
| -// // Print the following details name, capital, flag, using forEach function |
| 34 | +} |
| 35 | +//Q3 |
| 36 | +// Print the following details name, capital, flag, using forEach function |
37 | 37 |
|
38 |
| -// var xml3=new XMLHttpRequest(); |
39 |
| -// xml3.open("GET","https://restcountries.com/v3.1/all"); |
40 |
| -// xml3.send(); |
41 |
| -// xml3.onload=function(){ |
42 |
| -// console.log("------------------------!Finished 2rd!--------------------"); |
43 |
| -// console.log("------------------------!Starting 3rd!--------------------"); |
44 |
| -// var data=xml3.response; |
45 |
| -// var res=JSON.parse(data); |
46 |
| -// res.forEach(element => { |
47 |
| -// console.log(element.name); |
48 |
| -// console.log(element.flag); |
49 |
| -// console.log(element.capital); |
50 |
| -// }); |
| 38 | +var xml3=new XMLHttpRequest(); |
| 39 | +xml3.open("GET","https://restcountries.com/v3.1/all"); |
| 40 | +xml3.send(); |
| 41 | +xml3.onload=function(){ |
| 42 | + console.log("------------------------!Finished 2rd!--------------------"); |
| 43 | + console.log("------------------------!Starting 3rd!--------------------"); |
| 44 | + var data=xml3.response; |
| 45 | + var res=JSON.parse(data); |
| 46 | + res.forEach(element => { |
| 47 | + console.log(element.name); |
| 48 | + console.log(element.flag); |
| 49 | + console.log(element.capital); |
| 50 | + }); |
51 | 51 |
|
52 |
| -// } |
53 |
| -// //Q4 |
54 |
| -// //Print the total population of countries using reduce function |
| 52 | +} |
| 53 | +//Q4 |
| 54 | +//Print the total population of countries using reduce function |
55 | 55 |
|
56 |
| -// var xml4=new XMLHttpRequest(); |
57 |
| -// xml4.open("GET","https://restcountries.com/v3.1/all"); |
58 |
| -// xml4.send(); |
59 |
| -// xml4.onload=function(){ |
60 |
| -// console.log("------------------------!Finished 3rd!--------------------"); |
61 |
| -// console.log("------------------------!Starting 4th!--------------------"); |
62 |
| -// var data=xml4.response; |
63 |
| -// var res=JSON.parse(data); |
| 56 | +var xml4=new XMLHttpRequest(); |
| 57 | +xml4.open("GET","https://restcountries.com/v3.1/all"); |
| 58 | +xml4.send(); |
| 59 | +xml4.onload=function(){ |
| 60 | + console.log("------------------------!Finished 3rd!--------------------"); |
| 61 | + console.log("------------------------!Starting 4th!--------------------"); |
| 62 | + var data=xml4.response; |
| 63 | + var res=JSON.parse(data); |
64 | 64 |
|
65 |
| -// var total=res.reduce((pop,full)=>pop+full.population,0) |
66 |
| -// console.log(total); |
67 |
| -// console.log(res); |
68 |
| -// } |
| 65 | + var total=res.reduce((pop,full)=>pop+full.population,0) |
| 66 | + console.log(total); |
| 67 | + console.log(res); |
| 68 | +} |
69 | 69 |
|
70 |
| -// // Q5 |
71 |
| -// // Print the country that uses US dollars as currency. |
| 70 | +// Q5 |
| 71 | +// Print the country that uses US dollars as currency. |
72 | 72 | var xml5=new XMLHttpRequest();
|
73 | 73 | xml5.open("GET","https://restcountries.com/v3.1/all");
|
74 | 74 | xml5.send();
|
|
0 commit comments