We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 62c03ee commit 6546da2Copy full SHA for 6546da2
1 file changed
Programs/Basic/cal.js
@@ -0,0 +1,32 @@
1
+
2
+//npm install prompt-sync
3
4
+// Import prompt-sync
5
+const prompt = require("prompt-sync")();
6
7
+// Take inputs from user
8
+let num1 = Number(prompt("Enter first number: "));
9
+let operator = prompt("Enter operator (+, -, *, /): ");
10
+let num2 = Number(prompt("Enter second number: "));
11
12
+let result;
13
14
+// Perform calculation based on operator
15
+if (operator === "+") {
16
+ result = num1 + num2;
17
+} else if (operator === "-") {
18
+ result = num1 - num2;
19
+} else if (operator === "*") {
20
+ result = num1 * num2;
21
+} else if (operator === "/") {
22
+ if (num2 !== 0) {
23
+ result = num1 / num2;
24
+ } else {
25
+ result = "Error: Division by zero!";
26
+ }
27
+} else {
28
+ result = "Invalid operator!";
29
+}
30
31
+// Show result
32
+console.log(`Result: ${result}`);
0 commit comments