
Calculadora super basica
JavaScript
Actualizado el 17 de Marzo del 2018 por Anonymous (35 códigos) (Publicado el 8 de Marzo del 2017)
11.214 visualizaciones desde el 8 de Marzo del 2017
<!DOCTYPE html>
<html>
<head>
<title>Calculadora basica</title>
<style>
form{
background-color:white;
}
input[type="text"]{
background-color:black;
border:0px;
width:250px;
height: 40px;
font-size: 20px;
color: white;
margin-bottom: 5px;
}
input[type="button"]{
width:60px;border:0px;
height: 60px;
color: white;
background-color:cornflowerblue;
font-size: 18px;
font-weight: bold;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
margin-bottom: 5px;
}
body{
background-color:#f1f1f1;
}
</style>
</head>
<body>
<center>
<h1>Calculadora Basica</h1>
<form name="f1"><br>
<input type="text" name="txtcaja"><br>
<input type="button" onclick="escribir('1')" value="1">
<input type="button" onclick="escribir('2')" value="2">
<input type="button" onclick="escribir('3')" value="3"> <input type="button" onclick="escribir('+')" value="+"><br>
<input type="button" onclick="escribir('4')" value="4">
<input type="button" onclick="escribir('5')" value="5">
<input type="button" onclick="escribir('6')" value="6"> <input type="button" onclick="escribir('-')" value="-"><br>
<input type="button" onclick="escribir('7')" value="7">
<input type="button" onclick="escribir('8')" value="8">
<input type="button" onclick="escribir('9')" value="9"> <input type="button" onclick="escribir('*')" value="*"><br>
<input type="button" onclick="escribir('0')" value="0">
<input type="button" onclick="escribir('.')" value=".">
<input type="button" onclick="document.f1.reset()" value="C">
<input type="button" onclick="calcular()" value="="><br>
</form>
</center>
<script>
function escribir(n){
var caja = document.f1.txtcaja.value;
document.f1.txtcaja.value=caja + n;
}
function calcular(){
var caja = document.f1.txtcaja.value;
document.f1.txtcaja.value=eval(caja);
}
</script>
</body>
</html>