EXERCISE 2: Conditionals - Temperature Converter

Assignment

Create a temperature converter that:

  1. Asks the user for a temperature value using prompt()
  2. Asks the user for the unit (C for Celsius, F for Fahrenheit) using prompt()
  3. Converts the temperature to the opposite unit:
    If input is Celsius, convert to Fahrenheit:
    F = (C × 9/5) + 32

    If input is Fahrenheit, convert to Celsius:
    C = (F - 32) × 5/9
  4. Displays the result using document.write()

Requirements:

  • Use if/else statements to check the unit
  • Convert the prompt input to a number using Number() or parseInt()
  • Handle invalid inputs gracefully (you can display an error message)
  • Display the result in a clear format: "X°C is equal to Y°F" or vice versa
  • Use an external JavaScript file (script.js) linked to your HTML

Create an index.html file and a script.js file with your solution.