Created
January 27, 2021 08:23
-
-
Save pk/f88c1223a23d6396b91a5611df2acd49 to your computer and use it in GitHub Desktop.
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 lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<style> | |
.feld1 { | |
margin: 20px; | |
} | |
.feld2 { | |
margin: 20px; | |
} | |
</style> | |
<script> | |
function getFieldValue(field) { | |
const element = document.getElementById(field); | |
return parseInt(element.value); | |
} | |
function updateResultElement(value) { | |
const element = document.getElementById("ergebnis"); | |
element.value = value; | |
} | |
function plus() { | |
var summe = getFieldValue("feld1") + getFieldValue("feld2"); | |
updateResultElement(summe); | |
} | |
function minus() { | |
var differenz = getFieldValue("feld1") - getFieldValue("feld2"); | |
updateResultElement(differenz); | |
} | |
function mal() { | |
var produkt = getFieldValue("feld1") * getFieldValue("feld2"); | |
updateResultElement(produkt); | |
} | |
function dividiert() { | |
var quotient = getFieldValue("feld1") / getFieldValue("feld2"); | |
updateResultElement(quotient); | |
} | |
</script> | |
</head> | |
<body> | |
<center> | |
<h1>Taschenrechner</h1> | |
<p> | |
Eingabefeld 1: <input id="feld1" type="number" /> | |
<br> | |
<br> | |
Eingabefeld 2: <input id="feld2" type="number" /> | |
<br> | |
<br> | |
<button class="plus" onclick="plus()">+</button> | |
<button class="minus" onclick="minus()"> - </button> | |
<button class="mal" onclick="mal()"> * </button> | |
<button class="dividiert" onclick="dividiert()"> / </button> | |
<br> | |
<br> | |
Ergebnis: <input id="ergebnis" type="number" readonly /> | |
</center> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So few changes
int
won't apply here, it's dynamically typed