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 4: JavaScript
  8. Exercise 6: JavaScript I

Exercise 6: JavaScript I

Condições de conclusão
Aberto: quarta-feira, 2 abr. 2025, 08:00
Vencimento: quarta-feira, 9 abr. 2025, 23:59

Exercise 6: JavaScript 1

Upload a html file named USPnumber1.USPnumber2.html.

Choose one of the two exercises below:

Simple JavaScript Calculator

Instructions:

  1. Open your preferred code editor or browser-based environment, 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. In the JavaScript section, declare the following variables:

    • num1: A number variable to store the first operand.
    • num2: A number variable to store the second operand.
    • operation: A string variable to store the chosen operation (addition, subtraction, multiplication, or division).
    • result: A number variable to store the result of the operation.
  4. Write a function called performOperation that takes num1, num2, and operation as arguments. This function should perform the specified operation using a conditional statement (e.g., if-else or switch statement) and return the result.

  5. Test your performOperation function with different values for num1, num2, and operation. For example:

    • num1 = 5, num2 = 3, operation = "add" should return 8.
    • num1 = 7, num2 = 2, operation = "subtract" should return 5.
    • num1 = 3, num2 = 4, operation = "multiply" should return 12.
    • num1 = 10, num2 = 2, operation = "divide" should return 5.
  6. Display the result of each test case using console.log() or by appending the result to the HTML document using DOM manipulation.

  7. (Optional) Create a simple user interface with input fields and buttons to allow users to enter their own values for num1, num2, and operation. When the user clicks the "Calculate" button, display the result of the operation on the screen.


Not So Simple Calculator

Instructions:

  1. Open your preferred code editor or browser-based environment, 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 a simple user interface with the following elements:

    • Two input fields for numbers (operands)
    • A dropdown menu for selecting an operation (addition, subtraction, multiplication, division)
    • A button labeled "Calculate"
    • An area to display the result (e.g., a <div> element)
  4. In the JavaScript section, create a function called calculate that takes two numbers (operands) and an operation as arguments. This function should use a switch statement to perform the appropriate calculation based on the operation and return the result.

  5. Add an event listener to the "Calculate" button. When the button is clicked, read the values from the input fields and the dropdown menu, call the calculate function with these values, and display the result in the designated area.

  6. Implement error handling to deal with invalid inputs, such as non-numeric values, empty fields, or division by zero. Display an error message to the user when such issues are detected.

  7. (Optional) Add keyboard support, allowing the user to perform calculations by pressing the "Enter" key. Also, implement additional functionality, such as a "Clear" button to reset the input fields and result area, or the ability to chain multiple operations together.


◄ Quiz 3
Exercise 7: JavaScript II ►

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

                • TarefaExercise 6: JavaScript I

              • Module 5: DOM & Events

              • Module 6: AJAX Calls

              • 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