Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda