# Node.js Mini Calculator

okay you can follow me for create mini calculator with nodejs

1. first open your gitbash
    
2. go to your folder
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757297044107/4593053c-fc59-4095-bd07-191297dae660.png align="center")
    
3. create file input2.js and fill in the file as follows
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757297061901/b9d80b55-6d77-40ac-a7fc-76de53830ed7.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757297092907/77fb4792-ac56-4cd4-a98f-840e02312953.png align="center")
    
4. create file calculator and fill like this
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757297395543/cef1617c-35f4-4467-a585-6ee6ad34a4dd.png align="center")
    
    and this code for content file
    
    ```javascript
    import { inputText, closeInput } from "./input2.js";
    
    console.clear();
    console.log("  Calculator Console  ");
    
    let isRunning = true;
    
    while (isRunning) {
     console.log("\nChoose Operation:");
     console.log("1. addition");
     console.log("2. Subtraction");
     console.log("3. Multiplication");
     console.log("4. Division");
     console.log("0. Exit");
    
     const choice = await inputText("Enter a Choice (0-4)");
     switch (choice) {
      case "0": {
       isRunning = false;
       console.log("Thank you, Program finished.");
       break;
      }
      case "1":
      case "2":
      case "3":
      case "4": {
        const a = Number(await inputText("Enter the first number "));
        const b = Number(await inputText("Enter the second number "));
        switch (choice) {
         case "1": {
          console.log(`Result: ${a} + ${b} = ${a + b}`);
          break;
         }
         case "2": {
          console.log(`Result: ${a} - ${b} = ${a - b}`);
          break;
         }
         case "3": {
          console.log(`Result: ${a} * ${b} = ${a * b}`);
         }
         case "4": {
          if (b === 0) {
           console.log("❌ cannot divide by 0");
          } else {
           console.log(`Result: ${a} / ${b} = ${a / b}`);
          }
          break;
         }
        }
       break;
      }
     default:
       console.log("Invalid choice, Please try again!");
     }
    }
    ```
    
5. test your code or your program
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757298633857/3bec08ff-d8c7-4213-a61b-4862b274c506.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757298654490/f63e6fd0-04a3-4ae2-aa23-4d94f67e4455.png align="center")
    
    if you want to exit from program you can click ctrl + c
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757298815820/aebbd3b4-22a1-4350-bcaf-a9725441a52b.png align="center")
    
    you have left the program.
    

End !!

thank you, and follow me for more content about IT specifically backend.
