var proc = document.getElementById('process'); proc.addEventListener('click', function(e) { var L = document.getElementById('left').value; var R = document.getElementById('right').value; if (isNaN(L)) { alert(L + 'is not a number'); } else if (isNaN(R)) { alert(R + 'is not a number'); } else if (R > 5 || L > 5) { alert('Input cannot exceed 5'); } else if (R < 1 || L < 1) { alert('Input must be at least 1'); } else { var D = 'D' + L.toString(); var S = 'S' + R.toString(); LED(D); LED(S); } }, false); function LED(x) { var dex = document.getElementById('dex'); var sin = document.getElementById('sin'); switch (x) { case 'D1': dex.classList.remove('x-0', 'x-2', 'x-3', 'x-4', 'x-5'); dex.classList.add('x-1'); break; case 'D2': dex.classList.remove('x-0', 'x-1', 'x-3', 'x-4', 'x-5'); dex.classList.add('x-2'); break; case 'D3': dex.classList.remove('x-0', 'x-1', 'x-2', 'x-4', 'x-5'); dex.classList.add('x-3'); break; case 'D4': dex.classList.remove('x-0', 'x-1', 'x-2', 'x-3', 'x-5'); dex.classList.add('x-4'); break; case 'D5': dex.classList.remove('x-0', 'x-1', 'x-2', 'x-3', 'x-4'); dex.classList.add('x-5'); break; case 'S1': sin.classList.remove('x-0', 'x-2', 'x-3', 'x-4', 'x-5'); sin.classList.add('x-1'); break; case 'S2': sin.classList.remove('x-0', 'x-1', 'x-3', 'x-4', 'x-5'); sin.classList.add('x-2'); break; case 'S3': sin.classList.remove('x-0', 'x-1', 'x-2', 'x-4', 'x-5'); sin.classList.add('x-3'); break; case 'S4': sin.classList.remove('x-0', 'x-1', 'x-2', 'x-3', 'x-5'); sin.classList.add('x-4'); break; case 'S5': sin.classList.remove('x-0', 'x-1', 'x-2', 'x-3', 'x-4'); sin.classList.add('x-5'); break; default: dex.classList.remove('x-1', 'x-2', 'x-3', 'x-4', 'x-5'); dex.classList.add('x-0'); sin.classList.remove('x-1', 'x-2', 'x-3', 'x-4', 'x-5'); sin.classList.add('x-0'); break; } }
body { font: 400 16px/1.2'Consolas'; color: lime; background: #444; } fieldset { width: 335px; border: 2px ridge lime; } input { text-align: center; font: inherit; color: lime; background: #000; } .x-0, .x-1, .x-2, .x-3, .x-4, .x-5 { background: url(https://glpjt.s3.amazonaws.com/so/digit/0-5.png) no-repeat; } .x-0 { background-position: 0 0 !important; width: 18px; height: 24px; } .x-1 { background-position: 0 -25px; width: 18px; height: 24px; } .x-2 { background-position: 0 -50px; width: 18px; height: 24px; } .x-3 { background-position: 0 -75px; width: 18px; height: 24px; } .x-4 { background-position: 0 -100px; width: 18px; height: 24px; } .x-5 { background-position: 0 -125px; width: 18px; height: 24px; } #led { display: inline-table; width: 40px; object-fit: contain; } .digit { width: 18px; height: 24px; border: 1px inset #0F9; position: relative; top: -18px; z-index: 1; display: table-cell; }
<form id="twoDigit" name="twoDigit"> <fieldset> <legend>twoDigit</legend> <input id="left" name="left" type="number" min="1" max="5" step="1" /> <input id="right" name="right" type="number" min="1" max="5" step="1" /> <input id="process" name="process" type="button" value="Process Number" /> <output id="led" name="led"> <span id="dex" class="digit x-0"></span> <span id="sin" class="digit x-0"></span> </output> </fieldset> </form>