Skip to content

Commit b24ac29

Browse files
committed
Fourth commit
1 parent 73863c4 commit b24ac29

File tree

2 files changed

+62
-63
lines changed

2 files changed

+62
-63
lines changed

index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
<title>Document</title>
77
</head>
88
<body>
9-
<h1>HEloo</h1>
9+
<h1>This is day 7 Task answer</h1>
10+
<p>See the console for answer</p>
1011
<script src="script.js"></script>
1112
</body>
1213
</html>

script.js

+60-62
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();
@@ -77,10 +77,8 @@ xml5.onload=function(){
7777
console.log("------------------------!Starting 5th!--------------------");
7878
var data=xml5.response;
7979
var res=JSON.parse(data);
80-
var mapping=res.map((val)=>val.currencies)
81-
var dollars=mapping.map((val)=>console.log(val))
8280

83-
84-
85-
81+
var currency = res.filter((value)=> value.currencies && value.currencies.USD)
82+
console.log(currency)
83+
currency.forEach((value)=>console.log(value.name.common))
8684
}

0 commit comments

Comments
 (0)