Skip to main content

Temperature Calculator

Problem Statement

Create a program that allows the user to enter a temperature in Celsius and convert it to Fahrenheit. The program should have a simple user interface that includes an input field for the temperature and a button to submit the temperature. When the user clicks the button, the program should display the temperature in Fahrenheit. The program should also include a button that allows the user to convert the temperature from Fahrenheit to Celsius.

img.png

Acceptance Criteria

  • The program should have an HTML file with the required user interface elements (input fields, dropdown, buttons) styled with CSS.
  • The program should have a JavaScript function for converting Celsius to Fahrenheit.
  • The program should have a JavaScript function for converting Fahrenheit to Celsius.
  • When the user enters a temperature value and clicks a conversion button, the program should display the converted value.
  • 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 parseFloat() function to convert a string to a number. i.e. parseFloat('1.5')
  • fahrenheit = celsius * 9/5 + 32
  • celsius = (fahrenheit - 32) * 5/9
  • Use the toFixed() method to round the result to a specific number of decimal places. i.e. result.toFixed(2)