logo javascript

Javascript Course for Beginners

Instructor: Ivan Lourenço Gomes

List of Exercises # 5

1) Populate the below select box with the list of countries of the world. The task should be divided in two parts:

  • Create a function to get countries via AJAX from the following API: https://restcountries.eu/rest/v2/all
  • Create a function to add the <option> element for each country.


  • When a country is selected, use local storage to make it selected the next time the page is loaded.



    2) The JSON below represents a list of courses. Each course has a title and an array of reviews. Create a function to parse the json, add another property for the average rating of each course, then return a new JSON with the updated object.

    Use Try/Catch/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".
  • If the course has less than 5 reviews, the average rating property should receive the value: "Not enough reviews yet.".
  • Otherwise, the property should receive the average rating of the course rounded to 1 decimal place.
  •                     
    
        var courses = '[{"title": "PHP","reviews": []},{"title": "Javascript","reviews": [5,5,4.5,4,5,5,5,4.5]
            },{"title": "Python","reviews": [5,5,4,4,5,3,5,4,4,5]},{"title": "Machine Learning",
            "reviews": [5,5,4.5]}]';
    
                        
                    


    3) Add a new functionality to the country selector of exercise # 1. When the country is selected list below it the public holidays for that country in the previous year. Use the layout below:

    Country: Italy

    Year: 2019

    To get the data about the holidays, use the Holiday API. You will need to sign up for a free API key.

    Contents