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

218
Views
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
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!