calculadora_no terminada.html 1.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<style>
		table{
			width: 50%;
			margin: auto;
		}
		td{
			padding: 30px;
		}
	</style>
	<script type="text/javascript">
		var n = "";
		var a1 = 0;
		function capturar(a){
			b = a;
		}
		function mostrar(){
			var dis = document.getElementById("display");
			
			if (b=="1" || b=="2" || b=="3" || b=="4" || b=="5" || b=="6" || b=="7" || b=="8" || b=="9" || b=="0") {
				n = n + b;
				dis.innerHTML = n;
			}
			if (b=="+") {
				dis.innerHTML = "";
				a1 = a1 + parseInt(n);
				n = "";
			}
			if (b=="-") {
				dis.innerHTML = "";
				if (a1!=0) {
					a1 = a1 - parseInt(n);
					n = "";
				}
			}
			if (b=="x") {
				dis.innerHTML = "";
				a1 = a1 * parseInt(n);
				n = "";
			}
			if (b=="=") {
				dis.innerHTML = a1;
			}	
		}
	</script>
</head>
<body>
	<table border="1">
		<tr>
			<td colspan="4" id="display"></td>
		</tr>
		<tr>
			<td onclick="capturar('1'); mostrar()">1</td><td onclick="capturar('2'); mostrar()">2</td><td onclick="capturar('3'); mostrar()">3</td><td onclick="capturar('+'); mostrar()">+</td>
		</tr>
		<tr>
			<td onclick="capturar('4'); mostrar()">4</td><td onclick="capturar('5'); mostrar()">5</td><td onclick="capturar('6'); mostrar()">6</td><td onclick="capturar('-'); mostrar()">-</td>
		</tr>
		<tr>
			<td onclick="capturar('7'); mostrar()">7</td><td onclick="capturar('8'); mostrar()">8</td><td onclick="capturar('9'); mostrar()">9</td><td onclick="capturar('x'); mostrar()">x</td>
		</tr>
		<tr>
			<td onclick="capturar('0'); mostrar()" id="">0</td><td onclick="capturar('ce'); mostrar()"><-ce</td><td onclick="capturar('='); mostrar()" colspan="2">=</td>
		</tr>
	</table>
</body>
</html>