Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
Simple CLI calculator in js (least amount of code, using built-in functions only)

I'm trying to build the following calculator in every language and js raises questions.

This is my calculator in python3 that just works in 2 lines using the built-in eval() function:

#!/usr/bin/env python3
while True:
    print(eval(input("Calculate: "))

enter image description here

My goal is to reproduce this calculator with the least amount of code and only using the built-in functions of the given language.

I'm a rookie in js and this is how far I've got:

#!/usr/bin/env node
while(true){
    console.log(eval(prompt("Calculate: ")));
}

This is only working in theory and I understand that if I use Node as an interpreter I need to import prompt() and eval() functions to work but I'd like to avoid that because they aren't built-in and I thought I'd ask here first about the best approach.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Eval is already a native part of nodejs. Prompt, however, is not so simple, unfortunately. There is no trivial way to do this. I'd recommend to use a minimal library like prompt-sync instead.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!