calculadora.html 1.85 KB
Newer Older
Nelson Ruiz committed
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
<html>
<head>
	<script>
		//funcion que muestra lo que se selecciona en la pantalla
		function digitos(val)
		{
			document.getElementById("resultado").value+=val
		}
		
		//funcion que evalua la caena de entrada y lo evalua
		function resolver()
		{
			let x = document.getElementById("resultado").value
			let y = eval(x)
			document.getElementById("resultado").value = y
		}
		
		//limpia la pantalla
		function clr()
		{
			document.getElementById("resultado").value = ""
		}
	</script>
	

</head>

<body>
	<div class = title >Calculadora</div>
	<table border="4">
		<tr>
			<td colspan="5"><input type="text" id="resultado"/></td>
			
			<td><input type="button" value="c" onclick="clr()"/> </td>
		</tr>
		<tr>
		
			<td><input  type="button" value="1" onclick="digitos('1')"/> </td>
			<td><input type="button" value="2" onclick="digitos('2')"/> </td>
			<td><input type="button" value="3" onclick="digitos('3')"/> </td>
			<td><input type="button" value="/" onclick="dis('/')"/> </td>
		</tr>
		<tr>
			<td><input type="button" value="4" onclick="digitos('4')"/> </td>
			<td><input type="button" value="5" onclick="digitos('5')"/> </td>
			<td><input type="button" value="6" onclick="digitos('6')"/> </td>
			<td><input type="button" value="-" onclick="digitos('-')"/> </td>
		</tr>
		<tr>
			<td><input type="button" value="7" onclick="digitos('7')"/> </td>
			<td><input type="button" value="8" onclick="digitos('8')"/> </td>
			<td><input type="button" value="9" onclick="digitos('9')"/> </td>
			<td><input type="button" value="+" onclick="digitos('+')"/> </td>
		</tr>
		<tr>
			<td><input type="button" value="." onclick="digitos('.')"/> </td>
			<td><input type="button" value="0" onclick="digitos('0')"/> </td>
			<td><input type="button" value="=" onclick="resolver()"/> </td>
			<td><input type="button" value="*" onclick="digitos('*')"/> </td>
		</tr>
	</table>
</body>
</html>