Skip to content

Instantly share code, notes, and snippets.

@afr-dt
Created May 8, 2015 06:10
Show Gist options
  • Save afr-dt/0939d5436e18209c3c6f to your computer and use it in GitHub Desktop.
Save afr-dt/0939d5436e18209c3c6f to your computer and use it in GitHub Desktop.
Calculadora básica en JS
<!DOCTYPE html>
<html lang="es-MX">
<head>
<meta charset = 'utf-8'>
<title>Calcu</title>
</head>
<body>
<center>
<script>
var operation;
var number1, number2;
do
{
number1 = prompt('Introduce el primer número');
if (isNaN(number1))
{
alert('El valor introducido no es un número')
};
}while(isNaN(number1))
do
{
number2 = prompt('Introduce el segundo número');
if (isNaN(number2))
{
alert('El va introducido no es un número')
};
}while(isNaN(number2))
number1 = parseInt(number1);
number2 = parseInt(number2);
operation = prompt('Elige las opciones: \n + Sumar\n - Restar\n * Multiplicar\n / Dividir\n % Modulo');
switch(operation)
{
case '+': document.write(number1 + number2); break;
case '-': document.write(number1 - number2); break;
case '*': document.write(number1 * number2); break;
case '/': document.write(number1 / number2); break;
case '%': document.write(number1 % number2); break;
default: document.write('Operación no valida');
}
</script>
</center>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment