Last active
August 29, 2015 14:11
-
-
Save s0ren/14b3008f69c3635bb9dd to your computer and use it in GitHub Desktop.
Temperaturomregner med Range/slider
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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Temperaturomregner</title> | |
<script type="text/javascript" src="temperatur.js"></script> | |
<script type="text/javascript"> | |
var clickCelsius = function() | |
{ | |
degCelsius = document.querySelector("#celsius").value; | |
var degFahrenheit = celciusToFahrenheit(degCelsius); | |
document.querySelector("#fahrenheit").value = degFahrenheit; | |
} | |
var clickFahrenheit = function() | |
{ | |
degFahrenheit = document.querySelector("#fahrenheit").value; | |
var degCelsius = fahrenheitToCelsius(degFahrenheit); | |
document.querySelector("#celsius").value = degCelsius; | |
} | |
var slideCelsius = function() | |
{ | |
var celsiusRange = document.querySelector("#celsius_"); | |
var fahrenheitRange = document.querySelector("#fahrenheit_"); | |
var degCelsius = celsiusRange.value; | |
var degFahrenheit = celciusToFahrenheit(degCelsius); | |
console.log(degCelsius + "°C = " + degFahrenheit + "°F"); | |
fahrenheitRange.value = degFahrenheit; | |
document.querySelector("#celsius").value = degCelsius; | |
document.querySelector("#fahrenheit").value = degFahrenheit; | |
} | |
var slideFahrenheit = function() | |
{ | |
var celsiusRange = document.querySelector("#celsius_"); | |
var fahrenheitRange = document.querySelector("#fahrenheit_"); | |
var degFahrenheit = fahrenheitRange.value; | |
var degCelsius = fahrenheitToCelsius(degFahrenheit); | |
console.log(degCelsius + "°C = " + degFahrenheit + "°F"); | |
//fahrenheitRange.value = degFahrenheit; | |
celsiusRange.value = degCelsius; | |
document.querySelector("#celsius").value = degCelsius; | |
document.querySelector("#fahrenheit").value = degFahrenheit; | |
} | |
</script> | |
<style> | |
div { | |
width: 40%; | |
border: 1%; | |
margin: 2%; | |
float:left; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Temperaturomregner</h1> | |
<p>Omregner temperaturer fra grader Celsius til grader Fahrenheit, fra Fahrenheit til Celsius. Se console.log. Tryk på f12.</p> | |
<div> | |
<input type="text" id="celsius"> | |
<input type="range" id="celsius_" min="-273" max="273" onchange="slideCelsius()" oninput="slideCelsius()"> | |
<button onClick="clickCelsius()" >Til Fahrenheit -></button> | |
</div> | |
<div> | |
<input type="text" id="fahrenheit"> | |
<input type="range" id="fahrenheit_" min="-273" max="273" onchange="slideFahrenheit()" oninput="slideFahrenheit()"> | |
<button onClick="clickFahrenheit()"><- Til Celsius</button> | |
</div> | |
<script type="text/javascript"> | |
// Se http://da.wikipedia.org/wiki/Fahrenheit | |
// °F = °C × 1,8 + 32 | |
console.log( celciusToFahrenheit(0) + "°F" ); | |
console.log( celciusToFahrenheit(20) + "°F" ); | |
// °C = (°F – 32) / 1,8 | |
console.log( fahrenheitToCelsius(0) + "°C" ); | |
console.log( fahrenheitToCelsius(20) + "°C" ); | |
</script> | |
</body> | |
</html> |
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
// JavaScript Document | |
// Se http://da.wikipedia.org/wiki/Fahrenheit | |
// °F = °C × 1,8 + 32 | |
var celciusToFahrenheit = function(degCel) | |
{ | |
var tempFahrenheit = degCel * 1.8 + 32; | |
return tempFahrenheit; | |
} | |
//console.log( celciusToFahrenheit(0) + "°F" ); | |
//console.log( celciusToFahrenheit(20) + "°F" ); | |
// °C = (°F – 32) / 1,8 | |
var fahrenheitToCelsius = function(degFahr) | |
{ | |
return (degFahr - 32) / 1.8; | |
} | |
//console.log( fahrenheitToCelsius(0) + "°C" ); | |
//console.log( fahrenheitToCelsius(20) + "°C" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment