Mahmoud Alhelou

Sustainable Development Researcher

298

3

Calculator

function calc() {

var num1 = Number(document.querySelector('#num1').value);

var num2 = Number(document.querySelector('#num2').value);

var select = document.querySelector('select');

var operator = select.options[select.selectedIndex].value; var result;
if (operator == 'sum') {

result = num1 + num2;

} else if (operator == 'sub') {

result = num1 - num2;

}else if (operator == 'multiply'){

result = num1 * num2;

}else if (operator == 'div'){

result = num1/num2;

} else { result = 'Invalid operator'; }
result1.innerHTML = result ;

}

Comments

Please sign in or sign up to comment.