-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,41 @@ | ||
let celsiusInput = document.querySelector('#celsius > input') | ||
let fahrenheitInput = document.querySelector('#fahrenheit > input') | ||
let kelvinInput = document.querySelector('#kelvin > input') | ||
let celsiusInput = document.querySelector('#celsiusInput'); | ||
let fahrenheitInput = document.querySelector('#fahrenheitInput'); | ||
let kelvinInput = document.querySelector('#kelvinInput'); | ||
let clearButton = document.querySelector('#clearButton'); | ||
|
||
let btn = document.querySelector('.button button') | ||
|
||
|
||
function roundNumber(number){ | ||
return Math.round(number*100)/100 | ||
function roundNumber(number) { | ||
return Math.round(number * 100) / 100; | ||
} | ||
|
||
function convertTemperatures() { | ||
let cTemp = parseFloat(celsiusInput.value); | ||
let fTemp = (cTemp * 9/5) + 32; | ||
let kTemp = cTemp + 273.15; | ||
|
||
/* Celcius to Fahrenheit and Kelvin */ | ||
celsiusInput.addEventListener('input', function(){ | ||
let cTemp = parseFloat(celsiusInput.value) | ||
let fTemp = (cTemp*(9/5)) + 32 | ||
let kTemp = cTemp + 273.15 | ||
|
||
fahrenheitInput.value = roundNumber(fTemp) | ||
kelvinInput.value = roundNumber(kTemp) | ||
}) | ||
|
||
|
||
/* Fahrenheit to Celcius and Kelvin */ | ||
fahrenheitInput.addEventListener('input', function(){ | ||
let fTemp = parseFloat(fahrenheitInput.value) | ||
let cTemp = (fTemp - 32) * (5/9) | ||
let kTemp = (fTemp -32) * (5/9) + 273.15 | ||
|
||
celsiusInput.value = roundNumber(cTemp) | ||
kelvinInput.value = roundNumber(kTemp) | ||
}) | ||
|
||
/* Kelvin to Celcius and Fahrenheit */ | ||
kelvinInput.addEventListener('input', function(){ | ||
let kTemp = parseFloat(kelvinInput.value) | ||
let cTemp = kTemp - 273.15 | ||
let fTemp = (kTemp - 273.15) * (9/5) + 32 | ||
|
||
celsiusInput.value = roundNumber(cTemp) | ||
fahrenheitInput.value = roundNumber(fTemp) | ||
}) | ||
|
||
fahrenheitInput.value = roundNumber(fTemp); | ||
kelvinInput.value = roundNumber(kTemp); | ||
} | ||
|
||
btn.addEventListener('click', ()=>{ | ||
celsiusInput.value = "" | ||
fahrenheitInput.value = "" | ||
kelvinInput.value = "" | ||
}) | ||
celsiusInput.addEventListener('input', convertTemperatures); | ||
fahrenheitInput.addEventListener('input', function() { | ||
let fTemp = parseFloat(fahrenheitInput.value); | ||
let cTemp = (fTemp - 32) * 5/9; | ||
let kTemp = (fTemp - 32) * 5/9 + 273.15; | ||
|
||
celsiusInput.value = roundNumber(cTemp); | ||
kelvinInput.value = roundNumber(kTemp); | ||
}); | ||
kelvinInput.addEventListener('input', function() { | ||
let kTemp = parseFloat(kelvinInput.value); | ||
let cTemp = kTemp - 273.15; | ||
let fTemp = (kTemp - 273.15) * 9/5 + 32; | ||
|
||
celsiusInput.value = roundNumber(cTemp); | ||
fahrenheitInput.value = roundNumber(fTemp); | ||
}); | ||
|
||
clearButton.addEventListener('click', function() { | ||
celsiusInput.value = ""; | ||
fahrenheitInput.value = ""; | ||
kelvinInput.value = ""; | ||
}); |