Skip to content

Commit ebb4a3f

Browse files
committed
Fourth commit
1 parent b24ac29 commit ebb4a3f

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

script.js

+57-57
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
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
33

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))
1313

1414

15-
// }
15+
}
1616

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
1919

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);
2828

2929

30-
// var population=res.filter((val)=>val.population<200000)
30+
var population=res.filter((val)=>val.population<200000)
3131

32-
// var populationres=population.map((val)=>console.log(val.name.common))
32+
var populationres=population.map((val)=>console.log(val.name.common))
3333

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
3737

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+
});
5151

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
5555

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);
6464

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+
}
6969

70-
// // Q5
71-
// // Print the country that uses US dollars as currency.
70+
// Q5
71+
// Print the country that uses US dollars as currency.
7272
var xml5=new XMLHttpRequest();
7373
xml5.open("GET","https://restcountries.com/v3.1/all");
7474
xml5.send();

0 commit comments

Comments
 (0)