scottfontenot
8/14/2017 - 12:29 AM

## javascript practice- calculator

javascript practice- calculator

``````var calculator = {

console.log(n1+n2);
},
subtract :function(n1,n2){
console.log(n1-n2);
},
multiplication : function(n1,n2){
console.log(n1*n2);
},
division : function(n1,n2){
console.log(n1/n2);
}
}
calculator.division(2,4);
calculator.multiplication(2,4);
calculator.subtract(2,4);

return n1+n2;
}

function subtract(n1,n2) {
return n1-n2;
}
function multiplication(n1,n2) {
return n1*n2;
}
function division(n1,n2) {
return n1/n2;
}*/

``````
``````function calculator(num1,num2,operation){
switch(operation) {
console.log(result);
break;
case 'subtract':
var result = subtract(num1,num2);
console.log(result);
break;
case 'multiplication':
var result = multiplication(num1,num2);
console.log(result);
break;
case 'division':
var result = division(num1,num2);
console.log(result);
break;
default:
break;
}
return n1+n2;
}
function subtract(n1,n2) {
return n1-n2;
}
function multiplication(n1,n2) {
return n1*n2;
}
function division(n1,n2) {
return n1/n2;
}
}
calculator(2,4,'subtract');
calculator(2,4,'multiplication');
calculator(2,4,'division');

``````
``````function calculator(num1,num2,operation){
switch(operation) {
break;
case 'subtract':
console.log(subtract(num1,num2));
break;
case 'multiplication':
console.log(multiplication(num1,num2));
break;
case 'division':
console.log(division(num1,num2));
break;
default:
break;
}
return n1+n2;
}
function subtract(n1,n2) {
return n1-n2;
}
function multiplication(n1,n2) {
return n1*n2;
}
function division(n1,n2) {
return n1/n2;
}
}
calculator(2,4,'subtract');
calculator(2,4,'multiplication');
calculator(2,4,'division');

``````
``````function calculator(num1,num2,operation){
switch(operation) {
break;
case 'subtract':
console.log(subtract(num1,num2));
break;
case 'multiplication':
console.log(multiplication(num1,num2));
break;
case 'division':
console.log(division(num1,num2));
break;
default:
break;
}
return n1+n2;
}
function subtract(n1,n2) {
return n1-n2;
}
function multiplication(n1,n2) {
return n1*n2;
}
function division(n1,n2) {
return n1/n2;
}
}
calculator(2,4,'subtract');
calculator(2,4,'multiplication');
calculator(2,4,'division');

``````
``````function calculator(num1,num2,operation){
switch(operation) {
break;
case 'subtract':
subtract(num1,num2);
break;
case 'multiplication':
multiplication(num1,num2);
break;
case 'division':
division(num1,num2);
break;
default:
break;
}
console.log(n1+n2);
}
function subtract(n1,n2) {
console.log(n1-n2);
}
function multiplication(n1,n2) {
console.log(n1*n2);
}
function division(n1,n2) {
console.log(n1/n2);
}
}
calculator(2,4,'subtract');
calculator(2,4,'multiplication');
calculator(2,4,'division');

``````
``````function calculator(num1,num2,operation){
switch(operation) {
console.log(num1 + num2);
break;
case 'subtract':
console.log(num1 - num2);
break;
case 'multiplication':
console.log(num1*num2);
break;
case 'division':
console.log(num1 / num2);
break;
default:
break;
}
}
calculator(2,4,'subtract');
calculator(2,4,'multiplication');
calculator(2,4,'division');

``````
``````function calculator(num1,num2,operation){
console.log(num1 + num2);
} else if (operation == 'subtract') {
console.log(num1 - num2);
} else if (operation == 'multiplication') {
console.log(num1*num2);
} else if (operation == 'division') {
console.log(num1 / num2);
}
}

calculator(2,4,'subtract');
calculator(2,4,'multiplication');
calculator(2,4,'division');``````
``````function calculator(num1,num2,operation){
console.log(num1 + num2);
}

//subtract operation
if(operation == 'subtract') {
console.log(num1 - num2);
}
//multiplication operation
if(operation == 'multiplication') {
console.log(num1*num2);
}
//division operation
if(operation == 'division') {
console.log(num1 / num2);
}
}