Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help making this functional to look like the examples :) JS of what I have: const getTodos = async (resource) => { return

I need help making this functional to look like the examples :)image text in transcribed

JS of what I have:

const getTodos = async (resource) => {

return new Promise((resolve, reject) => {

const request = new XMLHttpRequest();

request.addEventListener('readystatechange', () => {

if (request.readyState === 4 && request.status === 200) {

const data = JSON.parse(request.responseText);

resolve(data);

} else if (request.readyState === 4) {

reject('could not fetch the data');

}

});

request.open('GET', resource);

request.send()

})

};

const getCountryInfo = async (id) => {

const base = 'https://restcountries.eu/rest/v2/all?fields-name;region;subregion;topLevelDomain';

const query = `${id}?apikey=${key}`;

const response = await fetch(base + query);

const data = await response.json();

return data [0]

}

validate = function(){

var radio = document.getElementById("#countryinfo");

var isValid = false;

var htmlData = document.getElementById("#displayData");

for (var i = 0; i

if (radio[i].checked) {

isValid = true;

htmlData.innerHTML += "country: " + data[i].name +

" " + "region: " + data[i].region +

" " + "subregion: " + data[i].subregion +

" " + "top level domain: " + data[i].topLevelDomain;

console.log(2);

}

}

}})

HTML:

Country API Assignment

About Countries

Enter Request

Get info about the country (ex: Bermuda)

List all countries in a region (ex: Americas)

List all countries in a subregion (ex: North America)

Find country with top level domain (ex: ly)

I need event listeners to use a call function to handle what radio button does.

here's an example of what it needs to look like.image text in transcribedimage text in transcribedimage text in transcribed

Fourth radio button, country with a specific top level domain: About Countries Enter Request ly Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) Top Level Domain .ly is for Libya Following the steps in videos 87 through 92, connect to the "restcountries" API; get all countries filtering the data to get those 4 elements (see below about the JavaScript file). The callback function will log any error to the console, else it will create event listeners for each of the radio buttons. Those event listeners must be inside of the callback function to be able to access the data. Each event listener needs to get the user's input in the field, then call a function with the data and the input that will do the necessary work. HTML page The top heading is an h1 tag. The text "Enter Request" is a simple paragraph. Below that paragraph, use a form with an input tag of type "text", and 4 input tags of type "radio". Each radio button needs a label that explains its function, as shown above. To Second radio button, list of countries in a specinc region: About Countries Enter Request Americas o Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) Countries in region Americas Anguilla Antigua and Barbuda Argentina Aruba Bahamas Barbados Belize Bermuda Bottom of that screen, notice the count of countries listed in the region: Trinidad and Tobago Turks and Caicos Islands United States of America Uruguay Venezuela (Bolivarian Republic of) Count of countries in region Americas is 57 About Countries Enter Request states Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) About states country: United States Minor Outlying Islands region: Americas subregion: Northern America top level domain: .us country: Micronesia (Federated States of) region: Oceania subregion: Micronesia top level domain: .fm country: United States of America region: Americas subregion: Northern America top level domain: .us Loop through the data to find the appropriate matches. When there is a match, display it in the div below the form on the web page. When listing the region and subregion countries, count those that match, and after listing all of the countries in the region / subregion, display the count, as seen in the examples above. If there was About Countries Enter Request north america Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) Countries in subregion north america Count of countries in subregion north america is o That subregion was not found, check spelling About Countries Enter Request .uk Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) That domain was not found, check spelling -- no periods, please Notice that the domain should be typed as letters, not with a preceding period. The data from the API will include that period, so add it in the code before trying to match it to the data. This request could have 2 errors the user typed the period, or the Fourth radio button, country with a specific top level domain: About Countries Enter Request ly Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) Top Level Domain .ly is for Libya Following the steps in videos 87 through 92, connect to the "restcountries" API; get all countries filtering the data to get those 4 elements (see below about the JavaScript file). The callback function will log any error to the console, else it will create event listeners for each of the radio buttons. Those event listeners must be inside of the callback function to be able to access the data. Each event listener needs to get the user's input in the field, then call a function with the data and the input that will do the necessary work. HTML page The top heading is an h1 tag. The text "Enter Request" is a simple paragraph. Below that paragraph, use a form with an input tag of type "text", and 4 input tags of type "radio". Each radio button needs a label that explains its function, as shown above. To Second radio button, list of countries in a specinc region: About Countries Enter Request Americas o Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) Countries in region Americas Anguilla Antigua and Barbuda Argentina Aruba Bahamas Barbados Belize Bermuda Bottom of that screen, notice the count of countries listed in the region: Trinidad and Tobago Turks and Caicos Islands United States of America Uruguay Venezuela (Bolivarian Republic of) Count of countries in region Americas is 57 About Countries Enter Request states Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) About states country: United States Minor Outlying Islands region: Americas subregion: Northern America top level domain: .us country: Micronesia (Federated States of) region: Oceania subregion: Micronesia top level domain: .fm country: United States of America region: Americas subregion: Northern America top level domain: .us Loop through the data to find the appropriate matches. When there is a match, display it in the div below the form on the web page. When listing the region and subregion countries, count those that match, and after listing all of the countries in the region / subregion, display the count, as seen in the examples above. If there was About Countries Enter Request north america Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) Countries in subregion north america Count of countries in subregion north america is o That subregion was not found, check spelling About Countries Enter Request .uk Get info about the country (ex: Bermuda) List all countries in a region (ex: Americas) List all countries in a subregion (ex: Northern America) Find country with given top level domain (ex: ly) That domain was not found, check spelling -- no periods, please Notice that the domain should be typed as letters, not with a preceding period. The data from the API will include that period, so add it in the code before trying to match it to the data. This request could have 2 errors the user typed the period, or the

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions