Skip to content

Commit 7646fff

Browse files
committed
First commit
0 parents  commit 7646fff

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<h1>HEloo</h1>
10+
<script src="script.js"></script>
11+
</body>
12+
</html>

readme.MD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This day 6 task contains
2+
3+
Solving problems using array functions on rest countries data (https://restcountries.com/v3.1/all).
4+
Get all the countries from Asia continent /region using Filter function
5+
Get all the countries with a population of less than 2 lakhs using Filter function
6+
Print the following details name, capital, flag, using forEach function
7+
Print the total population of countries using reduce function
8+
Print the country that uses US dollars as currency.

script.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//Q1
2+
// Get all the countries from Asia continent /region using Filter function
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))
13+
14+
15+
}
16+
17+
// Q2
18+
// Get all the countries with a population of less than 2 lakhs using Filter function
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);
28+
29+
30+
var population=res.filter((val)=>val.population<200000)
31+
32+
var populationres=population.map((val)=>console.log(val.name.common))
33+
34+
}
35+
//Q3
36+
// Print the following details name, capital, flag, using forEach function
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+
});
51+
52+
}
53+
//Q4
54+
//Print the total population of countries using reduce function
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);
64+
65+
var total=res.reduce((pop,full)=>pop+full.population,0)
66+
console.log(total);
67+
console.log(res);
68+
}
69+
70+
// Q5
71+
// Print the country that uses US dollars as currency.
72+
var xml5=new XMLHttpRequest();
73+
xml5.open("GET","https://restcountries.com/v3.1/all");
74+
xml5.send();
75+
xml5.onload=function(){
76+
console.log("------------------------!Finished 4rd!--------------------");
77+
console.log("------------------------!Starting 5th!--------------------");
78+
var data=xml5.response;
79+
var res=JSON.parse(data);
80+
var mapping=res.map((val)=>val.currencies)
81+
var dollars=mapping.map((val)=>console.log(val))
82+
83+
84+
85+
86+
}

0 commit comments

Comments
 (0)