Ir para o conteúdo principal
e-Disciplinas
  • Disciplinas »
    2026 2025 2024 2023 2022 2021 2020 2019 2018 2017 2016 2015 2014 2013 2012 AACCs/FFLCH Pró-Reitoria de Pós-Graduação Outros
  • Suporte »
    Acesso Perfis Ouvintes Docentes Criação de Disciplinas da USP Documentação HelpDesk e Contato Guia de uso Sobre
  • Português - Brasil ‎(pt_br)‎
    Deutsch ‎(de)‎ English ‎(en)‎ Español - Internacional ‎(es)‎ Français ‎(fr)‎ Italiano ‎(it)‎ Português - Brasil ‎(pt_br)‎
  • Fechar
    Alternar entrada de pesquisa
  • Acessar

SCC0219 - Introdução ao Desenvolvimento Web (2025)

  1. Início
  2. Ambientes
  3. 2025
  4. ICMC
  5. SCC
  6. SCC0219-2025
  7. Module 6: AJAX Calls
  8. Exercise 12: Promises and async/await

Exercise 12: Promises and async/await

Condições de conclusão
Aberto: quarta-feira, 30 abr. 2025, 08:00
Vencimento: quarta-feira, 30 abr. 2025, 12:00

Weather Application

Upload a html file named USPnumber1.USPnumber2.html. 

Attention: If you need to upload a file after the deadline use late.USPnumber1.USPnumber2.html

Activity: Build a Simple Weather Application (70 minutes)

Objective: The goal of this activity is to apply the knowledge of asynchronous JavaScript, Promises, and Fetch API to build a simple weather application that fetches data from a public API and displays it.

Instructions:

  1. Open your preferred code editor or browser-based environments, such as JSFiddle or CodePen.

  2. Create an HTML file and include the necessary tags for a basic HTML structure (<!DOCTYPE>, <html>, <head>, <body>). Add a <script> tag inside the <head> or at the end of the <body> to write your JavaScript code.

  3. Create the following HTML structure for the weather application. If you want to use city names, call an API or save the latitude and longitude for, at least, 3 cities.

  • An input to find city coordinates by city name.
  • A button to fetch the city coordinates.
  • Input fields for users to enter a latitude and longitude.
  • A button to fetch and display the weather data.
  • An area (div, p, etc.) to display the weather data.
  1. Use the Fetch API to send a GET request to the Open-Meteo public API to get city coordinates by city name. The endpoint is http://geocoding-api.open-meteo.com/v1/search?name={cityName}. API Documentation 

  2. Use the Fetch API to send a GET request to the Open-Meteo public API to get the city by coordinates. The endpoint is http://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true. API Documentation 

  3. Implement the following functionality:

  • When the user clicks the "Fetch Coordinates" button, use the entered city name to fetch the weather data from the API. The fetched data should autocomplete the latitude and longitude inputs using the returned coordinates.
  • When the user clicks the "Fetch Weather" button, use the entered latitude and longitude to fetch the weather data from the API. Display the fetched data in the designated area. The displayed data should include latitude, longitude (or city name), temperature, weather condition (API Documentation), and an icon representing the weather condition.
  • For weather icons:
    • Use the icon map from GitHub (day time) OR
    • Use any 3 representative icons for Clear, Cloudy, Something Falling (Rain, Snow, Drizzle, etc)
  • Handle possible errors appropriately. If the fetch operation fails, display a user-friendly error message.
  1. As you work on the activity, discuss the implementation with your partner or group members. Ask for help or clarification from the instructor or teaching assistant if needed.

  2. Once the activity is completed, share your solution with the rest of the class and discuss any challenges you encountered or alternative approaches you discovered.

Remember, the goal of this activity is to practice working with async/await, Promises, and Fetch API. Enjoy and have fun!

(Note: For the sake of this activity, we don't consider the cross-origin (CORS) issues that might occur when making the API request. In a real-world scenario, you might need to handle this.)

Please note that the Open-Meteo API does not require an API key and is only used as an example. In real-world applications, always check the API's documentation and terms of use.


◄ Exercise 11: AJAX Calls
Exercise 13: React/Vue ►

Blocos

Pular Navegação
  • Início

    • e-Disciplinas

      • Meus Ambientes

      • Tags

      • Pesquisar

      • PáginaSobre

      • PáginaHelp Desk e Contato

      • PáginaGuia

    • Meus Ambientes

    • Ambientes

      • 2025

        • CENA

        • EACH

        • ECA

        • EE

        • EEFE

        • EEFERP

        • EEL

        • EERP

        • EESC

        • EP

        • ESALQ

        • FAU

        • FCF

        • FCFRP

        • FD

        • FDRP

        • FE

        • FEA

        • FEARP

        • FFCLRP

        • FFLCH

        • FM

        • FMBRU

        • FMRP

        • FMVZ

        • FO

        • FOB

        • FORP

        • FSP

        • FZEA

        • IAG

        • IAU

        • IB

        • ICB

        • ICMC

          • SMA

          • SME

          • 550

          • SSC

          • SCC

            • TCCs do SCC

            • SCC0211-2025

            • SCC5920--2025

            • SCC0124-201-2025

            • SCC0283-201-2025

            • SCC0271-201-2025

            • SCC0230-202-2025

            • SCC5878-2025

            • SCC0233-201-2025

            • SCC0295-201-2025

            • ED - SCC0122 - 2025

            • SCC0634-201-2025

            • SCC0245-201-2025

            • SCC0607-201-2025

            • SCC0220-201-2025

            • LabBD-SCC0641-2025

            • SCC0560-201-2025

            • SCC5836--2025

            • SCC0252-201-2025

            • SCC0219-201-2025

            • SCC0202-2025

            • SCC5977--2025

            • SCC5809--2025

            • SCC5960--2025

            • SCC5959--2025

            • SCC5952--2025

            • SCC0277-201-2025

            • SCC0218-2025

            • SCC0227/SCC0229--2025

            • SCC0505--2025

            • SCC5832--2025

            • SCC0205-202-2025

            • SCC0205-201-2025

            • SCC0502-201-2025

            • SCC0223-201-2025

            • SCC0207-2025

            • SCC0580-201-2025

            • SCC0302-2025

            • SCC5949--2025

            • SCC5982--2025

            • SCC0216-2025

            • SCC0219-2025

              • Geral

              • Group Assignment

              • Course Introduction

              • Module 1: HTTP Protocol

              • Module 2: HTML

              • Module 3: CSS

              • Module 4: JavaScript

              • Module 5: DOM & Events

              • Module 6: AJAX Calls

                • TarefaExercise 12: Promises and async/await

              • Milestone 1

              • Module 7: React or Vue

              • Module 8: Node.js/ExpressJS

              • Milestone 2

              • Module 9: NoSQL Databases

              • Final Presentations

              • Final Test

          • EST

          • MAI

          • SMA

        • IEB

        • IEE

        • IF

        • IFQSC

        • IFSC

        • IGc

        • IME

        • IO

        • IP

        • IPEN

        • IQ

        • IQSC

        • IRI

        • HRAC

        • MAC

        • MAE

        • MP

        • MZ

        • RUSP

      • 2026

      • 2024

      • 2023

      • 2022

      • 2021

      • 2020

      • 2019

      • 2018

      • 2017

      • 2016

      • 2015

      • 2014

      • 2013

      • 2012

      • Grupos de Estudos, Pesquisa e Outros

      • PRPG - Pró-Reitoria de Pós-Graduação

      • STI

Blocos suplementares

Você acessou como visitante (Acessar)
Fornecido por Moodle