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

113
Views
Necesito ayuda para entender este ejercicio de construcción

Estoy aprendiendo constructores, estoy tratando de resolver este ejercicio. Estoy tratando de seguir estas instrucciones. Pero no puedo hacer que todo el programa funcione. Estoy usando una instancia de para verificar el objeto de la moneda. Me pregunto si hay otra manera de hacer esto. Espero que las instrucciones sean lo suficientemente claras.

OBJETO MONEDA: Debe tener 1 propiedad y 2 métodos. Propiedades: Estado: debe ser 1 o 0 cabezas (1) o cruces (0) Métodos: flip(): debe asignar aleatoriamente un 0 o un 1 a la propiedad de estado toString() Según el estado, debe devolver la cadena "caras" o "cruces"

OBJETO GALLINERO: segunda función constructora, crea un objeto gallinero el gallinero debe tener un parámetro para la función Coop numChickens Coop necesita una propiedad y un método Propiedades: numChickens - el número total de pollos. Métodos: reunirEggs() - devuelve un número aleatorio 1-3 x numChickens Agregue las propiedades y métodos del gallinero aquí

MÁQUINA EXPENDEDORA DE ALIMENTOS PARA POLLOS: Dos propiedades y un método Propiedades: comida - La cantidad de comida en la máquina expendedora. Esto debería comenzar en 12. numCoins - número de monedas puestas en la máquina. Esto debería comenzar en 0. Métodos: dispensar (moneda) - dispensar 5 alimentaciones por cada moneda pasada al método. El parámetro de moneda debe ser un objeto de moneda del fabricante de monedas anterior. Si la moneda es válida Y hay 5 alimentos Y agrega +1 numCoins. Devuelva el número 5 o la comida restante en la máquina. Si la comida es 0 devuelve 0

 /** 1. Coin Constructor * Fill in the properties and methods inside of the coin function */ const Coin = function() { state: 0, flip: function () { this.state = Math.floor(Math.random() * 2) == 0 ? "tails" : "heads"; }, toString: function () { if (this.state === 0) { sides = "heads"; } else if (this.state === 1) { sides = "tails"; } return sides; }, }; /** 2. Chicken Coop Constructor, * fill in the properties and methods inside of the Coop function */ const Coop = function (numChickens) { this.numChickens = numChickens; this.gatherEggs = function () { return Math.floor(Math.random() * 3 + 1) * numChickens; }; }; /** 3. Feed Vending Machine Constructor, * fill in the properties and methods inside of the FeedMachine function */ const FeedMachine = function () { //Add the feed vending machine properties and methods here this.food = 12; this.numCoins = 0; this.dispense = function (coin) { if (coin instanceof Coin && this.food > 5) { this.food -= 5; this.numCoins += 1; return 5; } else if (!Coin) { return 0; } if (this.food === 0) { return 0; } else if (this.food < 5) { this.numCoins++; const restOfFood = this.food; this.food -= this.food; return restOfFood; } }; }; export { Coin, Coop, FeedMachine };
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!