funciones.js 3.23 KB
Newer Older
roshka committed
1 2 3
function variables() {
    var resultado = document.getElementById('resultado');
    var suma = document.getElementById('suma');
4
    var eliminar = document.getElementById('eliminar');
roshka committed
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
    var resta = document.getElementById('resta');
    var multi = document.getElementById('multi');
    var division = document.getElementById('division');
    var igual = document.getElementById('igual');
    var punto = document.getElementById('punto');
    var uno = document.getElementById('uno');
    var dos = document.getElementById('dos');
    var tres = document.getElementById('tres');
    var cuatro = document.getElementById('cuatro');
    var cinco = document.getElementById('cinco');
    var seis = document.getElementById('seis');
    var siete = document.getElementById('siete');
    var ocho = document.getElementById('ocho');
    var nueve = document.getElementById('nueve');
    var cero = document.getElementById('cero');
}
var operandor1;
var operandor2;
var operacion;
punto.onclick=function(e){
    resultado.textContent = resultado.textContent  + ".";
}
cero.onclick=function(e){
    resultado.textContent = resultado.textContent  + "0";
}
uno.onclick = function(e){
    resultado.textContent = resultado.textContent  + "1";
}
dos.onclick = function(e){
    resultado.textContent = resultado.textContent  + "2";
}
tres.onclick = function(e){
    resultado.textContent = resultado.textContent  + "3";
}
cuatro.onclick = function(e){
    resultado.textContent = resultado.textContent  + "4";
}
cinco.onclick = function(e){
    resultado.textContent = resultado.textContent  + "5";
}
seis.onclick = function(e){
    resultado.textContent = resultado.textContent  + "6";
}
siete.onclick = function(e){
    resultado.textContent = resultado.textContent  + "7";
}
ocho.onclick = function(e){
    resultado.textContent = resultado.textContent  + "8";
}
nueve.onclick = function(e){
    resultado.textContent = resultado.textContent  + "9";
}
57
eliminar.onclick = function(e){
roshka committed
58 59
    borrar();
}
60

roshka committed
61
resta.onclick = function(e){
62
    resultado.textContent = resultado.textContent + "-";
roshka committed
63 64
    operandor1 = resultado.textContent;
    operacion = "-";
65
    //borrar();
roshka committed
66 67
}
multi.onclick = function(e){
68
    resultado.textContent = resultado.textContent + "*";
roshka committed
69 70
    operandor1 = resultado.textContent;
    operacion = "*";
71
   // borrar();
roshka committed
72 73
}
division.onclick = function(e){
74
    resultado.textContent = resultado.textContent + "/";
roshka committed
75 76
    operandor1 = resultado.textContent;
    operacion = "/";
77
    //borrar();
roshka committed
78 79
}
igual.onclick = function(e){
80 81
    resultado.textContent = resultado.textContent;
    //borrar();
roshka committed
82 83
}
function borrar() {
84
    resultado.textContent= "";
roshka committed
85
}
86 87
function operaciones() {
    var ecuacion;
roshka committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101
    switch (operacion) {
        case "+":
            ecuacion = parseFloat(operandor1)+parseFloat(operandor2);
            break;
        case "-":
            ecuacion = parseFloat(operandor1)-parseFloat(operandor2);
            break;
        case "*":
            ecuacion = parseFloat(operandor1)*parseFloat(operandor2);
            break;    
        case "/":
            ecuacion = parseFloat(operandor1)/parseFloat(operandor2);
            break;
    }
102 103 104 105 106 107 108
    
}
suma.onclick = function(e){
    resultado.textContent = resultado.textContent + "+";
    operandor1 = resultado.textContent;
    operacion;
   // borrar();
roshka committed
109
}