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); }