# 06 Server-Side APIs: Weather Dashboard ## Your Task Third-party APIs allow developers to access their data and functionality by making requests with specific parameters to a URL. Developers are...

1 answer below »
# 06 Server-Side APIs: Weather Dashboard
## Your Task
Third-party APIs allow developers to access their data and functionality by making requests with specific parameters to a URL. Developers are often tasked with retrieving data from another application's API and using it in the context of their own. Your challenge is to build a weather dashboard that will run in the browser and feature dynamically updated HTML and CSS.
Use the [OpenWeather One Call API](https://openweathermap.org/api/one-call-api) to retrieve weather data for cities. Read through the documentation for setup and usage instructions. You will use `localStorage` to store any persistent data.
## User Story
```AS A travelerI WANT to see the weather outlook for multiple citiesSO THAT I can plan a trip accordingly```
## Acceptance Criteria
```GIVEN a weather dashboard with form inputsWHEN I search for a cityTHEN I am presented with current and future conditions for that city and that city is added to the search historyWHEN I view current weather conditions for that cityTHEN I am presented with the city name, the date, an icon representation of weather conditions, the temperature, the humidity, the wind speed, and the UV indexWHEN I view the UV indexTHEN I am presented with a color that indicates whether the conditions are favorable, moderate, or severeWHEN I view future weather conditions for that cityTHEN I am presented with a 5-day forecast that displays the date, an icon representation of weather conditions, the temperature, the wind speed, and the humidityWHEN I click on a city in the search historyTHEN I am again presented with current and future conditions for that city```
## Mock-Up
The following image shows the web application's appearance and functionality:
![The weather app includes a search option, a list of cities, and a five-day forecast and current weather conditions for Atlanta.](./Assets/06-server-side-apis-homework-demo.png)
## Grading Requirements
This homework is graded based on the following criteria:

### Technical Acceptance Criteria: 40%
* Satisfies all of the above acceptance criteria plus the following:

* Uses the OpenWeather API to retrieve weather data.

* Uses `localStorage` to store persistent data.
### Deployment: 32%
* Application deployed at live URL.
* Application loads with no errors.
* Application GitHub URL submitted.
* GitHub repository that contains application code.
### Application Quality: 15%
* Application user experience is intuitive and easy to navigate.
* Application user interface style is clean and polished.
* Application resembles the mock-up functionality provided in the homework instructions.
### Repository Quality: 13%
* Repository has a unique name.
* Repository follows best practices for file structure and naming conventions.
* Repository follows best practices for class/id naming conventions, indentation, quality comments, etc.
* Repository contains multiple descriptive commit messages.
* Repository contains quality readme file with description, screenshot, and link to deployed application.
## Review
You are required to submit BOTH of the following for review:
* The URL of the functional, deployed application.
* The URL of the GitHub repository. Give the repository a unique name and include a readme describing the project.
Answered Same DayMay 08, 2021

Answer To: # 06 Server-Side APIs: Weather Dashboard ## Your Task Third-party APIs allow developers to access...

Pulkit answered on May 09 2021
158 Votes
83502_assigned/Develop/app.js
let userInput;
let uvIndex;
let pastCities = JSON.parse(localStorage.getItem("cities")) || [];
let display = document.getElementById("cityInfo");
let fiveSelect = document.getElementById("fiveDay");
let citySelect = document.getElementById("pastCitie
s");
// API KEY : 4e5dbe7db2b5e9c8b47fa40b691443d5
//API call by city name: api.openweathermap.org/data/2.5/weather?q=
document.addEventListener("click", () => {
let target = event.target;
if (target.classList.contains("btn")) {
userInput = document.getElementById("citySearch").value;
// console.log(userInput)
displayWeather(userInput);
//empty out userInput
document.getElementById("citySearch").value = "";
}
});
const renderPastCity = (_) => {
//set to empty before every render
citySelect.innerHTML = "";
for (let i = 0; i < pastCities.length; i++) {
let cityNode = document.createElement("div");
cityNode.innerHTML = `${pastCities[i]}
`;
citySelect.append(cityNode);
}
};
const toFarenheit = (value) => {
value = (value * (9 / 5) - 459.67).toFixed(2);
return value;
};
//Capitalize first letter of every word in the string
const titleCase = (str) => {
let splitStr = str.toLowerCase().split(" ");
// console.log(splitStr)
for (let i = 0; i < splitStr.length; i++) {
splitStr[i] =
splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
}
return splitStr.join(" ");
};
const displayWeather = (userInput) => {
//pushing userInput to local storage
userInput = titleCase(userInput);
pastCities.push(userInput);
console.log(pastCities);
localStorage.setItem("cities", JSON.stringify(pastCities));
renderPastCity();
getCityWeather(userInput);
};
const getCityWeather = (userInput) => {
display.innerHTML = "";
fetch(
`https://api.openweathermap.org/data/2.5/weather?q=${userInput}&appid=4e5dbe7db2b5e9c8b47fa40b691443d5`
)
.then((response) => response.json())
.then(
({ main: { temp, humidity }, wind: { speed }, coord: { lon, lat } }) => {
let info = document.createElement("div");
temp = toFarenheit(temp);
// console.log(temp, humidity, speed, lon, lat)
info.innerHTML = `

${userInput} ${moment().format("MM/DD/YYYY")}


Temperature: ${temp} ºF


Humidity: ${humidity}


Wind Speed: ${speed} mph


`;
display.append(info);
getUvIndex(lon, lat);
getFiveDayForecast(lon, lat);
}
)
.catch((error) => console.error(error));
};
const getUvIndex = (lon, lat) => {
fetch(
`https://api.openweathermap.org/data/2.5/uvi?appid=4e5dbe7db2b5e9c8b47fa40b691443d5&lat=${lat}&lon=${lon}`
)
.then((response) => response.json())
.then(({ value }) => {
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here