Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temperature convert in Html css and javascript #5

Open
0rahul opened this issue Jun 13, 2021 · 1 comment
Open

Temperature convert in Html css and javascript #5

0rahul opened this issue Jun 13, 2021 · 1 comment

Comments

@0rahul
Copy link

0rahul commented Jun 13, 2021

in your tutorial it seems it works but in reality it didnt work why sir i am so desperate with this project and stopped here.
its about conversion for temperature .

@a-shahzad
Copy link

in your tutorial it seems it works but in reality it didnt work why sir i am so desperate with this project and stopped here.
its about conversion for temperature .

HTML

<title>temp conv</title>
<form id="tempCalc" onsubmit="calculateTemp(); return false">

    <label for="temp">Enter the temperature to convert</label>
   <br /> <input type="number" name="temp" id="temp">

    <select name="temp_diff" id="temp_diff">
        <option value="cel">°Celcius</option>
        <option value="fah">°Fahrenheit</option>
    </select> <br />

    <input type="submit" name="temp"> <br />

    <span id="resultContainer"></span>
</form>



<script src="script.js"></script>

CSS
@import url(https://fonts.googleapis.com/css2?family=Mulish:wght@300&display=swap);

  • {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Mulish", sans-serif;
    }

body {
width: 100vw;
height: 100vh;
background-color: #f8e7af;
display: grid;
place-items: center;
}

form {
background-color: #fab1a0;
padding: 80px;
width: 50%;
margin: 100px auto;
text-align: center;
-webkit-box-shadow: 0 10px 6px -6px #777;
-moz-box-shadow: 0 10px 6px -6px #777;
box-shadow: 0 10px 6px -6px #777;
}

#tempcalc label {
font-size: 30px;
}

#temp {
border: none;
padding: 10px;
height: 40px;
width: 100px;
font-size: 20px;
margin-top: 20px;
}

#temp_diff {
height: 40px;
border: none;
margin-top: 20px;
font-size: 15px;
vertical-align: top;
}

[type="submit"] {
height: 35px;
margin: 20px;
width: 100px;
font-size: 15px;
border: none;
background-color: black;
color: white;
}

#resultContainer {
font-size: 35px;
}

JavaScript
const calculateTemp = () => {
const numberTemp = document.getElementById('temp').value;

const tempSelected = document.getElementById('temp_diff');

const valueTemp = tempSelected.options[tempSelected.selectedIndex].value;

const celToFah = (cel) => {
    let fahrenheit = Math.round(cel * 9/5 + 32);
    return fahrenheit;
}

const fahToCel = (fah) => {
    let celcius = Math.round((fah - 32) * 5/9);
    return celcius;
}

let result;

if(valueTemp == 'cel') {
    result = celToFah(numberTemp);
    document.getElementById('resultContainer').innerHTML = `= ${result}°Fahrenheit`;
}
    else {
        result = fahToCel(numberTemp);
    document.getElementById('resultContainer').innerHTML = `= ${result}°Celcius`;
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants