Simple Calculator

Medium
16
37.2% Acceptance

Welcome to the React Calculator Lab! In this lab, your task is to create a basic calculator that performs addition, subtraction, and multiplication. This calculator will provide instant feedback on the operations performed.

Instructions

  1. Create Input Fields:
    • Design two input fields of type number.
    • The first input should have an id of num1 and a default value of 0.
    • The second input should have an id of num2 and a default value of 0.
  2. Display Output:
    • Have a paragraph tag with the id output where the result of the operations will be shown.
  3. Perform Operations:
    • Implement a button with the id add. When clicked, it should calculate the sum of num1 and num2 and display the result in the output paragraph tag.
    • Similarly, include buttons with ids subtract and multiply. The subtract button should compute the difference, while the multiply button should compute the product of num1 and num2.
  4. Reset Functionality:
    • Introduce a button with the id reset. Upon clicking, the output should be cleared, and both num1 and num2 should revert to their default values (0).

Tips

  • This lab focuses on DOM manipulation using React. Remember to update the state properly whenever any user interaction occurs.
  • Use React's controlled component pattern to link the input fields with the state.
  • Ensure you handle events correctly. Each button should have its respective event handler to perform the desired operation.
  • Test your application thoroughly after each step to ensure that all functionalities are working as expected.