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

222
Visualizações
How to send input in a filename passed as a command line argument in javascript

I'm writing code in JavaScript and there is an condition to send the input. program must accept input from two sources: a filename passed as a command line argument, like ./myprogram input.txt; input read from STDIN, like ./myprogram < input.txt.

Input and Output:
Given the following input:
Add Tom 4111111111111111 $1000
Add Lisa 5454545454545454 $3000
Add Quincy 1234567890123456 $2000
Charge Tom $500
Charge Tom $800
Charge Lisa $7
Credit Lisa $100
Credit Quincy $200

program must produce the following output:
Lisa: $-93
Quincy: error Tom: $500

I have this JS file which has three function add charge and credit but I'm not sure how to send input from command line to arguments to these function:

let obj = {};


    function add(num, name, limit){
        if(obj[num]){
            console.log("alreday in the system");
            return;
        }
        else {
            obj[num] = {"name": name, "balance": 0, "limit": limit};
            return obj;
        }
    }
    
    
    function charge(num, chargeAmmount){
        let cardBalance = obj[num].balance;
        let newBalance = cardBalance+chargeAmmount;
        if(obj[num] && obj[num].limit>newBalance){
              obj[num].balance = newBalance;
              return obj;
        }
        else {
            console.log("cannot charge it, either this card is not in the system or canrge ammount is greater then the limit");
            return;
        }
    
    }
    
    function credit(num, creditBalance){
        let cardBalance = obj[num].balance;
        if(obj[num]){
            let newBalance = cardBalance-creditBalance;
            obj[num].balance = newBalance;
            return obj;
      } else {
        console.log("not a valid card number");
        return;
    }
    
    }
about 4 years ago · Juan Pablo Isaza
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