Skip to main content

Sum of Two Numbers

Problem Statement

Create a program that allows the user to enter two numbers and display the sum of the two numbers. The program should have a simple user interface that includes two input fields for the numbers and a button to submit the numbers. When the user clicks the button, the program should display the sum of the two numbers.

Acceptance Criteria

  • The program should have an HTML file with the required user interface elements (input fields, button) styled with CSS.
  • The program should have a JavaScript function that adds two numbers.
  • When the user clicks the button, the program should add the two numbers and display the result to the user.
  • The program should handle any errors (e.g., entering a non-numeric value) gracefully and display an error message to the user.
  • The program should be well-documented with clear and concise comments explaining each part of the code.

Hints

  • Use the parseInt() function to convert a string to a number. i.e. parseInt('1')
  • Use the parseFloat() function to convert a string to a number. i.e. parseFloat('1.5')
  • Get the value of an input field using the value property. i.e. document.getElementById('input').value
  • Set the value of an input field using the value property. i.e. document.getElementById('paragraph').value = 'Hello World'