Package Exports
- adv_calculator
- adv_calculator/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (adv_calculator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Arithmetic Functions Module
A simple Node.js module providing basic arithmetic functions: addition, subtraction, multiplication, and division. This module is designed for educational purposes to demonstrate how to write and test JavaScript functions.
Table of Contents
Overview
This module includes the following arithmetic functions:
add(a, b): Returns the sum ofaandb.subtract(a, b): Returns the difference whenbis subtracted froma.multiply(a, b): Returns the product ofaandb.divide(a, b): Returns the quotient whenais divided byb. Throws an error ifbis zero.
Installation
To use this module in your project, follow these steps:
Clone the repository:
git clone https://github.com/TyRoopam9599/adv_calculator.gitNavigate to the project directory:
cd adv_calculatorInstall dependencies:
This project uses Mocha for testing. Install it along with other dependencies using:
npm install
Usage
You can use the functions by requiring the module in your Node.js application. Here’s how you can do it:
const { add, subtract, multiply, divide } = require('./index');
console.log(add(2, 3)); // Output: 5
console.log(subtract(5, 2)); // Output: 3
console.log(multiply(2, 3)); // Output: 6
console.log(divide(6, 2)); // Output: 3
// Handle division by zero
try {
console.log(divide(6, 0));
} catch (error) {
console.error(error.message); // Output: Cannot divide by zero
}