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

223
Vistas
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 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