0% found this document useful (0 votes)
8 views2 pages

Asynchronous JavaScript Practice Questions

The document outlines two practice questions for asynchronous JavaScript. The first question involves creating a web app that fetches and displays travel destinations from an API, including error handling for failed calls or empty data. The second question requires fetching weather data for various cities and logging specific details to the console.

Uploaded by

zaynmaliik149
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Asynchronous JavaScript Practice Questions

The document outlines two practice questions for asynchronous JavaScript. The first question involves creating a web app that fetches and displays travel destinations from an API, including error handling for failed calls or empty data. The second question requires fetching weather data for various cities and logging specific details to the console.

Uploaded by

zaynmaliik149
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Asynchronous Javascript Practice questions

Q 1. You have been hired by a travel agency to create a small web app that displays travel
destinations. The data for these destinations is available from an external API in JSON
format. Your task is to fetch the data, process it, and display the destinations dynamically on
the web page. Fetch the travel destinations data from the following API endpoint:

[Link]

JSON Format:
[
{
"id": 1,
"name": "Paris",
"country": "France",
"description": "The city of light with iconic landmarks like the Eiffel Tower.",
"image": "[Link]
},
{
"id": 2,
"name": "Tokyo",
"country": "Japan",
"description": "A bustling city known for its modern architecture and cherry blossoms.",
"image": "[Link]
}
]

 Create a <div> element with an ID of destinations to serve as a container for the


fetched data.
 For each destination, dynamically create a card-like structure using JavaScript and
append it to the container. The card should include:
o The destination name and country (e.g., "Paris, France") as a heading.
o A description of the destination.
o An image representing the destination.

 Style the cards minimally using CSS for better visual clarity (optional).

 Handle potential errors:

 If the API call fails, display an error message on the page.


 If the fetched data is empty, display a message saying "No destinations available."

Q 2. You are working on a weather dashboard application. The


weather data for different cities is available through an external
API. Your task is to fetch the data and process it to display specific
information in the console. Fetch the weather data from the
following API endpoint:
[Link]

JSON Format:
[
{
"city": "New York",
"temperature": 25,
"condition": "Sunny",
"humidity": 60
},
{
"city": "London",
"temperature": 18,
"condition": "Cloudy",
"humidity": 80
},
{
"city": "Tokyo",
"temperature": 22,
"condition": "Rainy",
"humidity": 90
}
]

Using JavaScript, fetch the JSON data from the API. Parse the data to extract the following
details for each city:

o City name
o Temperature
o Weather condition

Log the details to the console in the following format:

City: New York, Temperature: 25°C, Condition: Sunny


City: London, Temperature: 18°C, Condition: Cloudy
City: Tokyo, Temperature: 22°C, Condition: Rainy

You might also like