1+ //na pernei tin timi pou dinw
2+ const celciusInput = document . querySelector ( "#celcius > input" ) ; //dose tin timi--> input apo to celcius
3+ const fahrenheitInput = document . querySelector ( "#fahrenheit > input" ) ;
4+ const kelvinInput = document . querySelector ( "#kelvin > input" ) ;
5+ function roundNum ( num ) {
6+ return Math . round ( num * 100 ) / 100 ;
7+ }
8+ //event lesseners
9+ //px click or input
10+ //1. type of event 2. function
11+
12+ function celciusToFahrenheitAndKelvin ( ) {
13+ const cTemp = parseFloat ( celciusInput . value ) ; //apo string pou einai se arithmo
14+ const fTemp = ( cTemp * ( 9 / 5 ) ) + 32 ; //metatrepi se fahrenheit
15+ const kTemp = cTemp + 273.15 ;
16+ fahrenheitInput . value = roundNum ( fTemp ) ;
17+ kelvinInput . value = roundNum ( kTemp ) ;
18+ }
19+
20+ function fahreTocelciusAndKelvin ( ) {
21+ const fTemp = parseFloat ( fahrenheitInput . value ) ;
22+ const cTemp = ( fTemp - 32 ) * ( 5 / 9 ) ;
23+ const kTemp = ( fTemp + 459.67 ) * 5 / 9 ;
24+ celciusInput . value = roundNum ( cTemp ) ;
25+ kelvinInput . value = roundNum ( kTemp ) ;
26+
27+ }
28+ function kelvinToCelciusAndFahre ( ) {
29+ const kTemp = parseFloat ( kelvinInput . value ) ;
30+ const cTemp = kTemp - 273.15 ;
31+ const fTemp = 9 / 5 * ( kTemp - 273 ) + 32 ;
32+ celciusInput . value = roundNum ( cTemp ) ;
33+ fahrenheitInput . value = roundNum ( fTemp ) ;
34+ }
35+
36+
37+ function main ( ) {
38+ celciusInput . addEventListener ( "input" , celciusToFahrenheitAndKelvin ) ;
39+ fahrenheitInput . addEventListener ( "input" , fahreTocelciusAndKelvin ) ;
40+ kelvinInput . addEventListener ( "input" , kelvinToCelciusAndFahre ) ;
41+ }
42+ main ( ) ;
0 commit comments