Solution: lb_bc

Node.js·2 min read·Apr 17, 2025

Here is the commented solution for this project.

Set up the project

Create a file named lb_bc.js.

touch lb_bc.js

Implement an arithmetic calculation function

The objective of this part is to implement a function that performs basic arithmetic calculations between two operands and an operator.

Declare a function named calculate() that takes as parameter two operands (i.e. op1 and op2) and one operator (i.e. opr), and either returns the result of the appropriate operation or throws an error in case of a division by zero.

lb_bc.js
function calculate(op1, op2, opr) {  if (opr === '+') {    return op1 + op2;  } else if (opr === '-') {    return op1 - op2;  } else if (opr === '*') {    return op1 * op2;  } else if (opr === '/') {    if (op2 === 0) {      throw new Error('Error: Cannot divide by zero');

Unlock the full program 🚀

Pay once, own it forever.

149

30-day money-back guarantee

  • 13 modules
  • 113 lessons with full-code examples
  • 29 projects with commented solutions
  • All future lesson and project updates
  • Lifetime access

By submitting this form, you agree to the Terms & Conditions and Privacy Policy.