javaScript.js 1.05 KB
Newer Older
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

function init(){
  var calcular = document.getElementById("calcular");
  var x = document.getElementById("n1");
  var y = document.getElementById("n2");

  calcular.onclick = function() {
    x.textContent = parseInt(Math.random() * 10);
    y.textContent = parseInt(Math.random() * 10);



    calcular = parseInt(x.textContent) + parseInt(y.textContent);
    console.log("La suma de x más y: " + calcular);

    calcular = parseInt(x.textContent) - parseInt(y.textContent);
    console.log("La resta de x menos y: " + calcular);

    calcular = parseInt(x.textContent) * parseInt(y.textContent);
    console.log("La multiplicacion de  x por y: " + calcular);

    calcular = parseInt(x.textContent) / parseInt(y.textContent);
    console.log("La division de x entre y: " + calcular);

    calcular = Math.pow(parseInt(x.textContent), parseInt(y.textContent));
    console.log("x elevado a la potencia de y: " + calcular);

    calcular = parseInt(x.textContent) % parseInt(y.textContent);
    console.log("El resto de la división entera entre x e y: " + calcular);

  }
}