Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
43 changes: 43 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//add event listener to the button
let button = document.querySelector('button');
button.addEventListener('click', convert);

let conversionFunction = {
// return fahrenheit to celsius, kelvin, rankine
fahrenheit: {
fahrenheit: (fahrenheit) => fahrenheit,
celsius: (fahrenheit) => (((fahrenheit - 32) * 5) / 9).toFixed(2),
kelvin: (fahrenheit) => (((fahrenheit - 32) * 5) / 9 + 273.15).toFixed(2),
rankine: (fahrenheit) => (fahrenheit + 459.67).toFixed(2),
},
// return celsius to fahrenheit, kelvin, rankine
celsius: {
fahrenheit: (celsius) => ((celsius * 9 /5) + 32).toFixed(2),
celsius: (celsius) => celsius,
kelvin: (celsius) => (celsius + 273.15).toFixed(2),
rankine: (celsius) => ((celsius * 9/5) + 491.67).toFixed(2),
},
kelvin: {
//return kelvin to fahrenheit, celsius, rankine
fahrenheit: (kelvin) => ((kelvin - 273.15) * 9/5 + 32).toFixed(2),
celsius: (kelvin) => (kelvin - 273.15).toFixed(2),
kelvin: (kelvin) => kelvin,
rankine: (kelvin) => (kelvin * 1.8).toFixed(2),
},
rankine: {
//return rankine to fahrenheit, celsius,
fahrenheit: (rankine) => (rankine - 459.67).toFixed(2),
celsius: (rankine) => ((rankine - 491.67) * 5/9).toFixed(2),
kelvin: (rankine) => (rankine * 5/9).toFixed(2),
rankine: (rankine) => rankine,
},
};

function convert (){
let inputValue = parseFloat(document.querySelector('#inputValue').value);
let convertFrom = (document.querySelector('#temperature').value).toLowerCase();
let result = (conversionFunction[convertFrom]);
for (let prop in result){
document.getElementById(prop).innerText = (result[prop](inputValue));
}
}
67 changes: 67 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="converter">
<!-- h1 header Temperature Scale Convertor -->
<h1>Temperature Scale Converter</h1>

<!-- label tag for farenheit | value label and input | calculate button -->
<div class="converterForm">
<div class="converterFormElement">
<div class="display">
<label for="temperature">Scale</label>
</div>
<div>
<select name="temperature" id="temperature">
<option value="Fahrenheit" class="scale">Fahrenheit</option>
<option value="Celsius" class="scale">Celsius</option>
<option value="Kelvin" class="scale">Kelvin</option>
<option value="Rankine" class="scale">Rankine</option>
</select>
</div>

</div>
<div class="converterFormElement display" >
<label for="value">Value</label>
<input type="text" id="inputValue" name="inputValue">
</div>
<div class="converterFormElement">
<button type="button">Calculate</button>
</div>
</div>
<!-- result div - celsius -->
<div class="resultData">
<div>
<h2>Fahrenheit</h2>
<h3 id="fahrenheit" class="result"></h3>
</div>
<div>
<h2>Celsius</h2>
<h3 id="celsius" class="result"></h3>
</div>
<div>
<h2>Kelvin </h2>
<h3 id="kelvin" class="result"></h3>
</div>
<div>
<h2>Rankine</h2>
<h3 id="rankine" class="result"></h3>
</div>
</div>
</div>

<script src="app.js" async defer></script>
</body>
</html>
61 changes: 61 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
*{
box-sizing: border-box;
}
h1{
font-size: 3.5rem;
margin: auto;
}
h2{
font-size: 2rem;
}
label {
margin: .5rem;
}
input{
padding: .5rem;
}
button {
font-size: 1.5rem;
padding: .5rem 1.5rem;
background-color: #DBE8FC;
border: 1px solid #6C8EBF;
}
.converter {
margin: 5rem;
background-color: aliceblue;
display: grid;
grid-template-rows: repeat(3, 1fr);
text-align: center;
border: 2px solid #DBE8FC;;
}

.converterForm{
display: grid;
grid-template-columns: repeat(3, 1fr);


}

.converterFormElement {
margin: auto;
font-size: 1.5rem;

}

.result {
height: 2rem;
}
.resultData{
display: grid;
grid-template-columns: repeat(4, 1fr);
}

.display{
display: flex;
flex-direction: column;
}

#temperature {
font-size: 1.5rem;
padding: .5rem 1rem;
}