1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Document</ title >
7+ < link rel ="stylesheet " href ="/css/home.css ">
8+ </ head >
9+ < body >
10+
11+
12+ < header >
13+ < nav class ="navbar ">
14+ < a href ="home.html "> Home</ a >
15+ < a href ="about.html "> About</ a >
16+ < a href ="login.html "> Login</ a >
17+ < a href ="register.html "> Register</ a >
18+ </ nav >
19+ </ header >
20+
21+
22+ < div class ="temperature-converter-container ">
23+ < h2 > Temperature Converter</ h2 >
24+ < label for ="temperature "> Enter Temperature:</ label >
25+ < input type ="text " id ="temperature " placeholder ="Enter temperature ">
26+
27+ < label for ="unit "> Select Unit:</ label >
28+ < select id ="unit ">
29+ < option value ="Celsius "> Celsius to Fahrenheit</ option >
30+ < option value ="Fahrenheit "> Fahrenheit to Celsius</ option >
31+ </ select >
32+
33+ < button onclick ="convertTemperature() "> Convert</ button >
34+
35+ < p id ="result "> </ p >
36+
37+
38+ < script >
39+ function convertTemperature ( ) {
40+ const temperatureInput = document . getElementById ( 'temperature' ) . value ;
41+ const unit = document . getElementById ( 'unit' ) . value ;
42+ let resultText = '' ;
43+
44+ if ( temperatureInput === '' ) {
45+ resultText = 'Please enter a temperature!' ;
46+ } else {
47+ let temperature = parseFloat ( temperatureInput ) ;
48+ if ( unit === 'Celsius' ) {
49+ const fahrenheit = ( temperature * 9 / 5 ) + 32 ;
50+ resultText = `${ temperature } °C is equal to ${ fahrenheit . toFixed ( 2 ) } °F.` ;
51+ } else {
52+ const celsius = ( temperature - 32 ) * 5 / 9 ;
53+ resultText = `${ temperature } °F is equal to ${ celsius . toFixed ( 2 ) } °C.` ;
54+ }
55+ }
56+
57+ document . getElementById ( 'result' ) . innerText = resultText ;
58+ }
59+ </ script >
60+
61+ </ body >
62+ </ html >
0 commit comments