From f7d2e67d5d29f3a8599958579307d635bc0f15cb Mon Sep 17 00:00:00 2001 From: structix Date: Sun, 19 May 2019 11:58:44 +0200 Subject: [PATCH] Update --- uebung3/farbenlehre.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/uebung3/farbenlehre.html b/uebung3/farbenlehre.html index 80b395c..e1a50e3 100644 --- a/uebung3/farbenlehre.html +++ b/uebung3/farbenlehre.html @@ -26,6 +26,16 @@ btn.addEventListener("click", updateTable); + function toHex(farbstring) { + let tempint = parseInt(farbstring); + let temphex = tempint.toString(16); + if (tempint < 16) { + //hex Zahl hat nur eine Stelle + temphex = "0" + temphex; + } + return temphex; + } + function updateTable() { let table = document.getElementById("farben"); let row = table.insertRow(0); @@ -38,10 +48,10 @@ let g = gruen.value; let b = blau.value; - cell1.innerHTML = r; - cell2.innerHTML = g; - cell3.innerHTML = b; - cell4.innerHTML = "farbwert"; + cell1.innerHTML = toHex(r); + cell2.innerHTML = toHex(g); + cell3.innerHTML = toHex(b); + cell4.innerHTML = "#" + toHex(r) + toHex(g) + toHex(b); }