S
Slim-Shady
Guest
hi... I have made a simple calculator in html....
now i want to add a random button,,,which can do random operation on two numbers...operation like add,sub.div,mul...
i am giving u code and its output is ugly haha......
for random i used math.random() and when i add <script> tab in start notthing displays then...plzz also tell me why...i am beginner..
i want to make it like when we press random button on calculator....it generate a random number and the operation which is stored in array do the work
eg... if random number is 2...then the operation store in ran[2] do the operation...
<html>
<body>
<form name="calc">
<table border=4 bordercolor="#993366">
<tr><td>
<input type="text" Name="input" size="15">
var ran = new Array(4);
ran[1]="eval(calc.input.value +='+'")";
ran[2]="calc.input.value +='-'";
ran[3]="calc.input.value +=' * '";
ran[4]="calc.input.value +=' / '";
</td></tr>
<tr><td>
<input type="button" name=" one " value=" 1 "
onClick="calc.input.value +='1'">
<input type="button" name=" two " value=" 2 "
onClick="calc.input.value +='2'">
<input type="button" name=" three " value=" 3 "
onClick="calc.input.value +='3'">
<input type="button" name=" plus " value=" + "
onClick="calc.input.value +='+'">
<input type="button" name=" random " value=" ran "
onClick="calc.input.value +='eval(ran[parseInt(Math.random()*10)])'">
<br>
<input type="button" name="four" value=" 4 "
onClick="calc.input.value +='4'">
<input type="button" name="five" value=" 5 "
onClick="calc.input.value +='5'">
<input type="button" name="six" value=" 6 "
onClick="calc.input.value +='6'">
<input type="button" name="minus" value=" - "
onClick="calc.input.value +='-'">
<br>
<input type="button" name="seven" value=" 7 "
onClick="calc.input.value +='7'">
<input type="button" name="eight" value=" 8 "
onClick="calc.input.value +='8'">
<input type="button" name="nine" value=" 9 "
onClick="calc.input.value +='9'">
<input type="button" name="times" value=" x "
onClick="calc.input.value +=' * '">
<br>
<input type="button" name="clear" value=" c "
onClick="calc.input.value = ' ' ">
<input type="button" name="Zero" value=" 0 "
onClick="calc.input.value +=' 0 '">
<input type="button" name="Equ" value=" = "
onClick="calc.input.value = eval(calc.input.value)">
<input type="button" name="div" value=" / "
onClick="calc.input.value +=' / '">
<br>
</td></tr>
</table>
</form>
</body>
</html>
now i want to add a random button,,,which can do random operation on two numbers...operation like add,sub.div,mul...
i am giving u code and its output is ugly haha......
for random i used math.random() and when i add <script> tab in start notthing displays then...plzz also tell me why...i am beginner..
i want to make it like when we press random button on calculator....it generate a random number and the operation which is stored in array do the work
eg... if random number is 2...then the operation store in ran[2] do the operation...
<html>
<body>
<form name="calc">
<table border=4 bordercolor="#993366">
<tr><td>
<input type="text" Name="input" size="15">
var ran = new Array(4);
ran[1]="eval(calc.input.value +='+'")";
ran[2]="calc.input.value +='-'";
ran[3]="calc.input.value +=' * '";
ran[4]="calc.input.value +=' / '";
</td></tr>
<tr><td>
<input type="button" name=" one " value=" 1 "
onClick="calc.input.value +='1'">
<input type="button" name=" two " value=" 2 "
onClick="calc.input.value +='2'">
<input type="button" name=" three " value=" 3 "
onClick="calc.input.value +='3'">
<input type="button" name=" plus " value=" + "
onClick="calc.input.value +='+'">
<input type="button" name=" random " value=" ran "
onClick="calc.input.value +='eval(ran[parseInt(Math.random()*10)])'">
<br>
<input type="button" name="four" value=" 4 "
onClick="calc.input.value +='4'">
<input type="button" name="five" value=" 5 "
onClick="calc.input.value +='5'">
<input type="button" name="six" value=" 6 "
onClick="calc.input.value +='6'">
<input type="button" name="minus" value=" - "
onClick="calc.input.value +='-'">
<br>
<input type="button" name="seven" value=" 7 "
onClick="calc.input.value +='7'">
<input type="button" name="eight" value=" 8 "
onClick="calc.input.value +='8'">
<input type="button" name="nine" value=" 9 "
onClick="calc.input.value +='9'">
<input type="button" name="times" value=" x "
onClick="calc.input.value +=' * '">
<br>
<input type="button" name="clear" value=" c "
onClick="calc.input.value = ' ' ">
<input type="button" name="Zero" value=" 0 "
onClick="calc.input.value +=' 0 '">
<input type="button" name="Equ" value=" = "
onClick="calc.input.value = eval(calc.input.value)">
<input type="button" name="div" value=" / "
onClick="calc.input.value +=' / '">
<br>
</td></tr>
</table>
</form>
</body>
</html>