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

201
Views
¿Cómo acceder a una propiedad dentro de un objeto y usarla en otro método? javascript

Necesito crear un método para devolver el nombre de un cliente y el valor de la cuenta bancaria de la siguiente manera:

 *bank.printAccount('Sheldon'); // this should print 'Sheldon account is 0'*

Sin embargo, estoy luchando por descubrir cómo acceder a los clientes de la propiedad para usar en un método printAccount . Actualmente tengo esto:

 class Bank { constructor(){ this.customers = {}; } } Bank.prototype.addCustomer = function(customer){ this.customers[customer] = 0; } Bank.prototype.printAccount = function(){ }; var bank = new Bank(); bank.addCustomer('Sheldon'); bank.addCustomer('Bob');
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ahí tienes:

 class Bank { constructor() { this.customers = {}; } } Bank.prototype.addCustomer = function(customer) { this.customers[customer] = 0; } Bank.prototype.printAccount = function(customer) { console.log(this.customers[customer]) }; var bank = new Bank(); bank.addCustomer('Sheldon'); bank.addCustomer('Bob'); bank.printAccount('Sheldon'); bank.printAccount('Bob');

Probablemente necesitará agregar casos extremos en printAccount() como para verificar si el cliente existe o no.

Editar: Se eliminó la inicialización duplicada de customers .

about 4 years ago · Juan Pablo Isaza Report
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!