Skip to content

Commit dadd8a0

Browse files
Update Sum of Two Number.js
1 parent 3ed62d6 commit dadd8a0

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
const a = 10;
2-
const b = 20;
3-
const c = a + b;
4-
console.log(c)
1+
// Common Ways to Add Numbers In JavaScript
2+
3+
// 1. Normal Variable Addition (Direct Way)
4+
const a = 10;
5+
const b = 20;
6+
const sum = a + b;
7+
console.log("Addition of two number": sum);
8+
// output:
9+
// Addition of two number: 30
10+
11+
// 2. One-Line Addition (Used for Console testing or demo purpose)
12+
Console.log(10+5);
13+
// Output:
14+
// 15
15+
16+
// 3. Using "prompt()" It take Inputs from User, Convert to number and Perform Addition – Runs only in browser
17+
let a = Number(prompt("Enter first number:"));
18+
let b = Number(prompt("Enter second number:"));
19+
console.log("Sum:", a + b);
20+
// Output:
21+
// Enter frist number: 2
22+
// Enter second number: 8
23+
// Sum: 10

0 commit comments

Comments
 (0)