# Create Simple Calculator With cml (Comand Line): For Node js

Assalamualaikum, today we are learning about create simple calculator with command line, lets go to we are project, before it read

# 1\. Add File Calculator

in this segmen we will create new file the name is `calculator.js`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757297992575/5e02307d-0b65-415f-9c05-58a59d66af5a.png align="center")

# 2\. Create Code In File

this code for we segmen

```javascript
import { getinput, closeInput } from "./input.js";
 
console.clear();
console.log("=== Kalkulator Console ===");
 
let jalan = true;
 
while (jalan) {
  console.log("\nPilih operasi:");
  console.log("1. Tambah");
  console.log("2. Kurang");
  console.log("3. Kali");
  console.log("4. Bagi");
  console.log("0. Keluar");
 
  const pilihan = await getinput("Masukkan pilihan (0-4)");
 
  switch (pilihan) {
    case "1": {
      const a = Number(await getinput("Masukkan angka pertama"));
      const b = Number(await getinput("Masukkan angka kedua"));
      console.log(`Hasil: ${a} + ${b} = ${a + b}`);
      break;
    }
    case "2": {
      const a = Number(await getinput("Masukkan angka pertama"));
      const b = Number(await getinput("Masukkan angka kedua"));
      console.log(`Hasil: ${a} - ${b} = ${a - b}`);
      break;
    }
    case "3": {
      const a = Number(await getinput("Masukkan angka pertama"));
      const b = Number(await getinput("Masukkan angka kedua"));
      console.log(`Hasil: ${a} * ${b} = ${a * b}`);
      break;
    }
    case "4": {
      const a = Number(await getinput("Masukkan angka pertama"));
      const b = Number(await getinput("Masukkan angka kedua"));
      if (b === 0) {
        console.log("❌ Tidak bisa dibagi 0");
      } else {
        console.log(`Hasil: ${a} / ${b} = ${a / b}`);
      }
      break;
    }
    case "0":
      jalan = false;
      console.log("Terima kasih, program selesai.");
      break;
    default:
      console.log("Pilihan tidak valid, coba lagi!");
  }
}
 
await closeInput();
```

this ui for file calculator.js

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757299614702/7d18d809-cd66-4a41-8869-aa09f408098b.png align="center")

# 3\. Running code

For running code we typing this

```bash
node calculator.js
```

then appear this

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1757299911832/488dd1e8-b2e9-4339-8699-f742a86d273e.png align="center")

# 4\. Closing

thanks for watching , and see you next time…
