Skip to content

Commit

Permalink
Multiply and Divide by 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongolding committed Oct 6, 2021
1 parent 92fe492 commit 6927402
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion templates/clicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@
}
}
}
function multiply(n) {
let binary = getBits();
let decimal = parseInt(binary, 2);
decimal = MAX === decimal ? 0 : decimal * n;
binary = decimal_2_base(decimal, 2);
setConversions(binary);
for (let i = 0; i < binary.length; i++) {
let digit = binary.substr(i, 1);
document.getElementById('digit' + i).value = digit;
if (digit === "1") {
document.getElementById('bulb' + i).src = "{{ imgBulbOn }}";
document.getElementById('butt' + i).innerHTML = "{{ msgTurnOff }}";
} else {
document.getElementById('bulb' + i).src = "{{ imgBulbOff }}";
document.getElementById('butt' + i).innerHTML = "{{ msgTurnOn }}";
}
}
}
</script>
{% endblock %}

Expand Down Expand Up @@ -185,7 +203,7 @@ <h1 class="text-center">Binary Math with Conversions</h1>
<td id="decimal">0</td>
<!-- Hack: display ASCII printable character(s) -->
<td><button type="button" id="sub1" onclick="add(-1)">-1</button></td>
<td><button type="button" id="divide2" onclick="divide(2)">/2</button></td>
<td><button type="button" id="divide2" onclick="multiply(0.5)">/2</button></td>

</tr>
</table>
Expand Down

0 comments on commit 6927402

Please sign in to comment.