JSFiddle - React, Tailwind, and code Playground
HTML
<div align="center">
<span style="font-weight:bold" size="20">Calculator</span>
<br>
<!-- Prints my name -->
<form name="MyName" id="form1" style="font-weight:bold" size="20">
<script>
document.write("Mallery, Cody");
</script>
</form>
<!-- functions -->
<!-- The Calculator! -->
<center><form>
<table border=4>
<tr>
<td>
<input name="display" id="input" size=25>
<br>
</td>
</tr>
<tr>
<td>
<input type="button" value=" 7 " onClick="addChar(this.form.display, '7')">
<input type="button" value=" 8 " onClick="addChar(this.form.display, '8')">
<input type="button" value=" 9 " onClick="addChar(this.form.display, '9')">
<input type="button" value=" / " onClick="addChar(this.form.display, '/')">
<br>
<input type="button" value=" 4 " onClick="addChar(this.form.display, '4')">
<input type="button" value=" 5 " onClick="addChar(this.form.display, '5')">
<input type="button" value=" 6 " onClick="addChar(this.form.display, '6')">
<input type="button" value=" * " onClick="addChar(this.form.display, '*')">
<br>
<input type="button" value=" 1 " onClick="addChar(this.form.display, '1')">
<input type="button" value=" 2 " onClick="addChar(this.form.display, '2')">
<input type="button" value=" 3 " onClick="addChar(this.form.display, '3')">
<input type="button" value=" - " onClick="addChar(this.form.display, '-')">
<br>
<input type="button" value=" 0 " onClick="addChar(this.form.display, '0')">
<input type="button" value=" N " onClick="changeSign(this.form.display)">
<input type="button" value=" + " onClick="addChar(this.form.display, '+')">
<input type="button" value=" C " onClick="this.form.display.value = 0 ">
<br>
<input type="button" value=" L " name="L" onClick="Loop(this.form.display.value)"
title="If the L button is pressed, the digit present in the results box will be looped through and added up to the 'digit plus 10'.For...
JavaScript
function addChar(input, character)
{
if(input.value == null || input.value == "0")
input.value = character;
else
input.value += character;
}
function changeSign(input)
{
if(input.value.substring(0, 1) == "-")
input.value = input.value.substring(1, input.value.length);
else
input.value = "-" + input.value;
}
function compute(form)
{
form.display.value = eval(form.display.value);
}
function Loop(input)
{
var num = parseInt(input) + 10;
var i=0;
var sum=0;
while(i < num)
{
sum=sum+i;
i++;
}
document.getElementById("input").value=sum;
// what's this for?
// document.forms[0].display.value=sum;
}