Codifíca.me | Desarrollo web | Programación | SEOCodifíca.me | Desarrollo web | Programación | SEO
  • Monetizar
    • Adsense
    • SEO
  • Desarrollo web
    • Php
    • WordPress
    • Blogger
    • Facebook (API)
      • Aplicación Test
      • Conectar con Facebook
      • Facebook en Español
      • Publicar Facebook
    • Google Maps
    • JavaScript
    • Opencart
    • Prestashop
    • XML
    • Flash
  • Bases de datos
    • Oracle
    • MySql
    • Data Mining
    • Forms
    • SGBD
  • Código
    • Android
    • Ensamblador
    • Código ensamblador
    • Java
    • ms-dos
    • Pro*C
    • Vb.net
  • Crear Blog
  • Cajon desastre
    • Redes
    • Arquitectura
    • Ubuntu
    • Hardware
    • Software
    • Consolas
    • Iphone
  • Tools
    • Get Backlinks
    • SQL 2 XML
    • Footprints enlaces

Mini calculadora en JavaScript

Práctica JavaScript de una mini calculadora con las siguentes funciones:

Integrar además en una sola calculadora los siguientes botones de operaciones matemáticas:

1) Operaciones unitarias (con un solo operando):
1.1) x^2 (número elevado al cuadrado)
1.2) 1/x (inverso del número)
1.3) sqrt(x) (raiz cuadrada del número)
1.4) parte_entera(x) (parte entera de x: si x es positivo devuelve Math.floor(x) y si es negativo devuelve -Math.ceil(x))

2) Operaciones binarias (con dos operandos):
2.1) +. -. *, / (suma, resta, multiplicación y división)
2.2) x^y (x elevado a y)

be1d80740ba5760b_640_-software

Este sería el código:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
 
    <!-- The style.css file allows you to change the look of your web pages.
         If you include the next line in all your web pages, they will all share the same look.
         This makes it easier to make new pages for your site. -->
    <link href="/style.css" rel="stylesheet" type="text/css" media="all">
 
 <title>Mini calculadora en JavaScript</title>
 
<script>
function calcula(operacion){
    var operando1 = document.calc.operando1.value;
    var operando2 = document.calc.operando2.value;
    var result = 0;
    if (operacion=='+' || operacion=='-'  || operacion=='*' || operacion=='/' )   {
      result = eval(operando1 + operacion + operando2);
    }
    if (operacion=='^'){
       result = operando1 * operando1;    
    }
    if (operacion=='I'){
       result = eval(1 / operando1);    
    }
    if (operacion=='R'){
       result = eval(sqrt(operando1));    
    }
    if (operacion=='F'){
       result = eval(Math.floor(operando1));    
    }    
    if (operacion=='E'){
       result = eval(Math.pow(operando1 , operando2));    
    }   
 
    document.calc.resultado.value = result;
}
</script> 
 
</head>
<body>
 
<form name="calc">
<input type="Text" name="operando1" value="0" size="12">
<br>
<input type="Text" name="operando2" value="0" size="12">
<br>
<input type="Button" name="" value=" + " onclick="calcula('+')">
<input type="Button" name="" value=" - " onclick="calcula('-')">
<input type="Button" name="" value=" X " onclick="calcula('*')">
<input type="Button" name="" value=" / " onclick="calcula('/')">
<input type="Button" name="" value=" x^2 " onclick="calcula('^')">
<input type="Button" name="" value=" 1/x " onclick="calcula('I')">
<input type="Button" name="" value=" sqrt(x) " onclick="calcula('R')">
<input type="Button" name="" value=" Math.floor " onclick="calcula('F')">
<input type="Button" name="" value=" x^y " onclick="calcula('E')">
<br>
Resultado:
<br>
<input type="Text" name="resultado" value="0" size="12">
</form> 
 
</body>
</html>

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <!-- The style.css file allows you to change the look of your web pages. If you include the next line in all your web pages, they will all share the same look. This makes it easier to make new pages for your site. --> <link href="/style.css" rel="stylesheet" type="text/css" media="all"> <title>Mini calculadora en JavaScript</title> <script> function calcula(operacion){ var operando1 = document.calc.operando1.value; var operando2 = document.calc.operando2.value; var result = 0; if (operacion=='+' || operacion=='-' || operacion=='*' || operacion=='/' ) { result = eval(operando1 + operacion + operando2); } if (operacion=='^'){ result = operando1 * operando1; } if (operacion=='I'){ result = eval(1 / operando1); } if (operacion=='R'){ result = eval(sqrt(operando1)); } if (operacion=='F'){ result = eval(Math.floor(operando1)); } if (operacion=='E'){ result = eval(Math.pow(operando1 , operando2)); } document.calc.resultado.value = result; } </script> </head> <body> <form name="calc"> <input type="Text" name="operando1" value="0" size="12"> <br> <input type="Text" name="operando2" value="0" size="12"> <br> <input type="Button" name="" value=" + " onclick="calcula('+')"> <input type="Button" name="" value=" - " onclick="calcula('-')"> <input type="Button" name="" value=" X " onclick="calcula('*')"> <input type="Button" name="" value=" / " onclick="calcula('/')"> <input type="Button" name="" value=" x^2 " onclick="calcula('^')"> <input type="Button" name="" value=" 1/x " onclick="calcula('I')"> <input type="Button" name="" value=" sqrt(x) " onclick="calcula('R')"> <input type="Button" name="" value=" Math.floor " onclick="calcula('F')"> <input type="Button" name="" value=" x^y " onclick="calcula('E')"> <br> Resultado: <br> <input type="Text" name="resultado" value="0" size="12"> </form> </body> </html>

Mini Calculadora en JavaScript















Resultado:


Mini calculadora en JavaScript
Vota esta entrada. Danos tu like!

Miguel Ber
Miguel Ber Software Developer

Ingeniero informático y desarrollador de aplicaciones web. Experto en desarrollo web, Webmaster, e-commerce y SEO.

Code is {poetry}
¿Necesitas un desarrollador? Contáctame!
¿Tienes alguna pregunta? Te respondemos ya!!

Deja un comentario Cancelar respuesta

Tu dirección de correo electrónico no será publicada.

Síguenos en las redes

Facebook
Twitter
Google+
Skype
GitHub
  • portatil ingeniero Mejores Laptops para Ingenieros y estudiantes de Ingeniería
  • sillas-gamming Las 20 mejores sillas gaming y de oficina
  • Los mejores ordenadores portátiles para estudiantes 2019
  • ideapad 310 Review Lenovo Portátil Ideapad 310
  • hp Opinión Portátil HP 250 G6 | Review
  • Ordenador Portátil Convertible – Acer SP513 – Intel Core i5 – 8 GB RAM – 256 GB SSD
codifica.me
Este sitio emplea cookies para prestar sus servicios, para personalizar anuncios y para analizar el tráfico. Si utilizas este sitio web, se sobreentiende que aceptas el uso de cookies..Aceptar Leer más
Privacidad y Política de Cookies