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

137
Views
Empuje aleatoriamente los nombres en una de las dos matrices

Tengo un objeto con dos matrices (_licky, _unlucky). y métodos que insertan nombres aleatoriamente en una de las dos matrices. Pero mi código no funciona por algún motivo... ¿Qué problema tiene mi código?

 const luckGame = { _lucky: [], _unlucky: [], pushGamer(name) { return name; }, getRandomNumber (random) { return random = Math.floor(Math.random() * 2); }, pushGamerIntoArray () { return { if (this.getRandomNumber() === 0 ) { this._lucky.push(this.pushGamer()); } else { this._unlucky.push(this.pushGamer()); } }; }, }; this.pushGamer('John'); this.pushGamer('Nick'); this.pushGamer('Maria'); this.pushGamer('Sarah'); this.pushGamer('Ron'); this.pushGamer('Lisa'); console.log(luckGame._lucky); console.log(luckGame._unlucky);

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Lo arreglé. Ahora funciona. ¡¡gracias a todos!!

 const luckGame = { _lucky: [], _unlucky: [], getRandomNumber (random) { return random = Math.floor(Math.random() * 2); }, pushGamerIntoArray (name) { if (this.getRandomNumber() === 0 ) { return this._lucky.push(name); } else { return this._unlucky.push(name); } }, }; luckGame.pushGamerIntoArray('John'); console.log(luckGame._lucky); console.log(luckGame._unlucky);
about 4 years ago · Juan Pablo Isaza Report

0

Hubo algunos pequeños errores de su parte. Lo he reescrito en una variante de clase. Funciona, pero aún mejoraría algunas cosas. Puedes probarlo un poco.

 const luckyGame = class { constructor() { this._lucky = [], this._unlucky = [] } pushGamer(name) { this.pushGamerIntoArray(name) } getRandomNumber (random) { return random = Math.floor(Math.random() * 2); } pushGamerIntoArray (newGamerName) { if (this.getRandomNumber() === 0 ) { this._lucky.push(newGamerName) } else { this._unlucky.push(newGamerName) } } getLuckies () { return this._lucky } getUnluckies () { return this._unlucky } } let luckygame = new luckyGame() luckygame.pushGamer('John'); luckygame.pushGamer('Nick'); luckygame.pushGamer('Maria'); luckygame.pushGamer('Sarah'); luckygame.pushGamer('Ron'); luckygame.pushGamer('Lisa'); luckygame.pushGamer('John'); console.log(luckygame.getLuckies()); console.log(luckygame.getUnluckies());

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!