Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# JavaLearing
Wnat to add new feature related to 101
# Simple Addition Program

This is a simple Node.js application that takes two numbers as input and displays their sum in the console.

## Setup and Installation

1. Make sure [Node.js](https://nodejs.org/) is installed on your system.
2. Clone or download this repository.
3. Open a terminal and navigate to the project directory.
4. Run `npm install` (no dependencies are required for this project, but this ensures the project is ready).

## Usage

1. Run the program using:

npm start

2. You will be prompted to enter two numbers.
3. The program will display their sum in the console.

## Example


Simple Addition Program
Enter the first number: 5
Enter the second number: 10

The sum of 5 and 10 is: 15


## License

This project is licensed under the ISC License.
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const readline = require('readline');

// Function to add two numbers
function addNumbers(a, b) {
return a + b;
}

// Create a readline interface for user input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

// Prompt user for input
console.log("Simple Addition Program");
rl.question('Enter the first number: ', (firstInput) => {
const num1 = parseFloat(firstInput);

// Check if the first input is a valid number
if (isNaN(num1)) {
console.log('Invalid input. Please enter a valid number.');
rl.close();
return;
}

rl.question('Enter the second number: ', (secondInput) => {
const num2 = parseFloat(secondInput);

// Check if the second input is a valid number
if (isNaN(num2)) {
console.log('Invalid input. Please enter a valid number.');
rl.close();
return;
}

// Compute and display the result
const result = addNumbers(num1, num2);
console.log(`\nThe sum of ${num1} and ${num2} is: ${result}`);

rl.close();
});
});
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "addition-program",
"version": "1.0.0",
"description": "A simple addition program that takes input and outputs the sum of two numbers.",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC"
}