Bria Collins

Bria Collins

  • 2k
  • 2
  • 150

Javascript using function with parameters, and return statement

Jan 22 2021 1:11 AM
<html>
<body>
<script>
let a = window.prompt("Enter a number: ");
let num = parseInt(window.prompt("Enter a number: "));
let num2 = parseInt(window.prompt("Enter a number: "));
function calc(val){
switch (a)
{
case '+':
return num+num2;
break;
case '-':
result = num1 - num2;
document.write("Difference is: " + result);
break;
case '*':
result = num1 * num2;
document.write("Product is: " + result);
break;
case '/':
result = num1 / num2;
document.write("Quotient is: " + result);
break;
default:
document.write("Error! operator is not correct");
break;
}
}
</script>
</body>
</html

Answers (2)