Assignment
Create a temperature converter that:
- Asks the user for a temperature value using
prompt() - Asks the user for the unit (C for Celsius, F for Fahrenheit) using
prompt() - 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 - Displays the result using
document.write()
Requirements:
- Use if/else statements to check the unit
- Convert the prompt input to a number using
Number()orparseInt() - 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.