Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda