Created
August 1, 2018 22:57
-
-
Save JoseJuan81/3837e1981d5468666408871a1f258403 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/cibugak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Crear un script que realice los procesos básicos de una calculadora: | |
// sumar, resta, multiplicar, dividir. | |
// Respuesta 1: | |
var suma = function (x, y) { | |
return x + y | |
} | |
var multiplica = function (x, y) { | |
return x * y | |
} | |
var resta = function (x, y) { | |
return x - y | |
} | |
var dividir = function (x, y) { | |
return x / y | |
} | |
console.log( | |
'Respuesta a 1:', | |
suma(4, 6), | |
multiplica(4, 6), | |
resta(4, 6), | |
dividir(4, 6), | |
) | |
// Respuesta 2: | |
class Calculator { | |
constructor(x, y) { | |
this.x = x; | |
this.y = y; | |
} | |
sum() { | |
return this.x + this.y | |
} | |
mul() { | |
return this.x * this.y | |
} | |
rest() { | |
return this.x - this.y | |
} | |
div() { | |
return this.x / this.y | |
} | |
} | |
var calcula = new Calculator(4, 6) | |
console.log( | |
'Respuesta 2:', | |
calcula.sum(), | |
calcula.mul(), | |
calcula.rest(), | |
calcula.div(), | |
) | |
//Respuesta 3 | |
class Calc { | |
constructor(){} | |
sum(x, y) { | |
return x + y; | |
}; | |
mul(x, y) { | |
return x * y; | |
}; | |
rest(x, y) { | |
return x - y; | |
}; | |
div(x, y) { | |
return x / y; | |
} | |
} | |
var cal = new Calc() | |
console.log( | |
'Respuesta 3:', | |
cal.sum(4, 6), | |
cal.mul(4, 6), | |
cal.rest(4, 6), | |
cal.div(4, 6), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment