<html>
<body>
<form>
<div id="celsius">
<input placeholder="celsius" type="number" />
</div>
<br /><br />
<div id="fahrenheit">
<input placeholder="fahrenheit" type="number" />
</div>
<br /><br />
<div id="kelvin">
<input placeholder="kelvin" type="number" />
</div>
<br /><br />
<input id="reset" type="reset" value="reset" />
</form>
</body>
</html>
#css code==>>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
input{
position: relative;
border: none;
outline: none;
color: #000;
border-radius: 5px;
padding: 6px;
left:20%;
}
input:hover{
box-shadow: 2px 2px 1px 1px #777;
}
::placeholder{
color: #aaa;
}
::-webkit-inner-spin-button,
::-webkit-outer-spin-button{
-webkit-appearance: none;
}
form{
padding: 10px;
width: 300px;
height: none;
line-height:20px;
height: initial;
border: 6px solid slateblue;
border-radius: 10px;
box-shadow: 1px 1px 1px 1px inset;
background: linear-gradient(to top, #2da2f0, #73f5e4);
}
#reset{
position: relative;
top: 20%;
left: 31%;
padding: 10px;
width: 100px;
border-radius: 5px;
border: none;
letter-spacing: 1px;
}
#reset:hover{
box-shadow: 2px 2px 4px #777;
transform: scale(1.4em);
}
#js code==>
const celsiusinput = document.querySelector('#celsius > input');
const fahrenheitinput = document.querySelector('#fahrenheit > input');
const kelvininput = document.querySelector('#kelvin > input');
function roundnum(num){
return Math.round(num*100)/100;
}
function ctofandk(){
const ctemp = parseFloat(celsiusinput.value);
const ftemp = (ctemp * (9/5)) + 32;
const ktemp = ctemp + 273.15;
fahrenheitinput.value =roundnum(ftemp);
kelvininput.value = roundnum(ktemp);
}
function ftocandk(){
const ftemp = parseFloat(fahrenheitinput.value);
const ctemp = (ftemp - 32) * (5/9);
const ktemp = (ftemp + 459.67) * 5/9;
celsiusinput.value = roundnum(ctemp);
kelvininput.value = roundnum(ktemp);
}
function ktocandf(){
const ktemp = parseFloat(kelvininput.value);
const ctemp = ktemp - 273.15;
const ftemp = 9/5 * (ktemp - 273) + 32;
celsiusinput.value = roundnum(ctemp);
fahrenheitinput.value = roundnum(ftemp);
}
function main(){
celsiusinput.addEventListener('input', ctofandk);
fahrenheitinput.addEventListener('input', ftocandk);
kelvininput.addEventListener('input', ktocandf);
}
main();
For Temperature Converter Web App: click here
Comments
Post a Comment