Hey, everyone, it's time to do our list of exercises, number five, so as always, I'm just going
to read the question, give you a few tips, and then I'm going to give you some time to solve it.
So, number one, populate the below select box with the list of countries of the world.
The task should be divided in two parts.
So first, create a function to get countries using Ajax from the following API.
So I'm giving you the Yooralla for the API.
And the second part is create a function to add the option element for each country.
So you need to create two functions here.
So if you inspect this element, you will see that this is a select box with with only one option inside.
So the first part of your work is going to be doing an AJAX requests for this API.
If you go to this address, you will see that you will receive a list of all countries in the world.
So all you have to do is looping through this list or this array and then adding every country has an
option of this select box.
So this would be pretty easy to do.
And now there's another part for this exercise, which it is when a country is selected, use local
storage to make it selected the next time the page is loaded.
So if I select a country here, let's say France, the next time I load the page, not only you need
to populate this list again, but you need to preselect friends, which is what is stored in the local
storage.
And every time you change the country, you just update the local storage.
So the next time the page loads, it loads with the previous country preselected.
Right.
So that's it for number one.
Number two, the Jason below represents a list of courses.
Each course has a title and an array of reviews.
Create a function to pass the Jason, add another property for the average rating of each course, then
return a new JSON with the updated object.
So here, for each course, you have an object.
So here's the object.
Actually, let me use another one as an example.
This one is good.
So here we have one property called Title, which is the title of the course in one property for the
reviews, which is just the list of reviews.
So what you have to do is pass this JSON, then go inside this object.
And for each course, you need to add the new property called average rating, which you are going to
calculate from this array.
But as you can see, some courses don't have any reviews like this one.
And there are also some extra rules.
So I want you to use, try, catch and throw to comply with the following rules if the course doesn't
have any reviews.
The average rating property should receive the value, no reviews.
So then instead of sending the average, you are just going to send a string with the text.
No reviews.
If the course says less than five reviews, the average rating property should receive the value.
Not enough reviews yet.
So if it's below five still, you won't calculate anything.
You are just going to send not enough reviews yet for this new property if the course has five reviews
or more so otherwise the property should receive the average rating of the course rounded to one decimal
place.
So what you can do here is just sending the new Jason to the console just so you can check if this is
right, if everything's right, if you have a Jason back with a new property for each of the courses,
then this is enough.
So, number three, add the new functionality to the country selector of exercise one.
So here you have this country selector that you are going to solve in exercise number one.
And now we are going to add something here.
So when the country is selected, I want you to list below it the public holidays for that country in
the previous year.
Use the layout below.
So let's say I go here, I see all the countries and I select Italy.
What I want you to do is just list this right below that select box where I can see the country that
I selected the previous year.
This is important because the API that we are going to use only works for the previous year.
So if you tried the current here, this is not going to work.
So I want you to use the previous here, which in this case is 2019.
And then you were going to list all the public holidays for that country, how are you going to do that?
You're going to use the holiday API.
So here's the link if you go inside here.
You need to get a free API key, it's really easy, you just click here, just leave your email and
you are going to receive an API key.
And then inside here, I want you to try to find the URL that you need to use so you can get the list
of public holidays for that country.
If you have any questions, just go to the video where I solve this exercise.
So then you see how to use this API.
But before you do that, just try to explore this API.
Just go to these menus here, try to find some documentation where you can see what the your and the
properties that you need to use for this request.
So that's it.
We only have three exercises, but this is going to take a bit more time than normally.
So good luck.
And when you're done, just go back here, because in the next video, I'm going to start solving these
exercises.
So I'll see you then.