Temperature Calculator

 index.html :

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="temp.css">
    <title>Temprature Counter</title>
</head>

<body>
    <div class="container">
        <div class="box">
            <h3> Convert <strong>Farenheight</strong> to <strong>Celcius</strong></h3>
            <div class="box1">
                <form id="tempCalc" onsubmit="calTemp(); return false" action="process.php">
                    <input type="number" id="number">
                    <select name="temp" id="temp">
                        <option class="temp_option" value="select">Select</option>
                        <option class="temp_option" value="c">Celcius</option>
                        <option class="temp_option" value="f">Farenheight</option>
                    </select>
                    <input id="btn" type="submit">Submit</input>
                    <br>
                    <span id="final"></span>
                </form>
                
            
    </div>
    <script src="temp.js"></script>
</body>

</html>

index.js


const calTemp = () => {
    
    const number = document.getElementById("number").value
    let ele = document.getElementById("temp")
    let selectedValue = ele.options[ele.selectedIndex].value
    console.log(selectedValue);
    if (selectedValue == 'c') {
        let result = Math.round(number * 9 / 5 + 32)
        console.log("converted to farehit ", result)
        document.getElementById("final").innerHTML = `${result} Farenheit`;
        

    }
    else if (selectedValue == 'f') {
        let result = Math.round(5 / 9 * (number - 32))
        console.log("converted to celcius ", result)
        document.getElementById("final").innerHTML = `${result} Celcius`
    }

    else {
        console.log("choose any option");
    }

}

index.css

*{
    padding0px;
    margin0px;
    box-sizingborder-box;
}
.container{
    height100vh;
    displayflex;
    flex-directioncolumn;
    background-colorrgb(209128128);
    displayflex
}
.box{
    marginauto;
    width500px;
    height300px;
    border2px solid rgb(255255255);
    displayflex;
    flex-directioncolumn;
    justify-contentcenter;
    text-aligncenter;
    background-colorblack;
}

h3{
    colorantiquewhite;
}
.box1 {
    displayflex;
    flex-directioncolumn
   marginauto;
   padding30px;
}
#number{
    font-size24px;
}

input,select {
    font-size10px;
    padding15px;
    margin5px;
}
button{
    display: flexbox;
    padding6px;
    margin20px;

}

#final{
    displayinline-block;
    padding10px;
    margin5px;
    colorwhite;
    font-size15px;
    ;
}






0 Comments