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

124
Views
¿Por qué este código Javascript detiene la ejecución en mi bucle for?

Estoy aprendiendo Javascript y escribí un pequeño programa. Tengo un método dentro de mi objeto con un bucle for. ¿Por qué mi consola muestra la salida cuando mi valor de combustible es 5? Todavía debería iterar a través del ciclo, ¿verdad?

 let car = {

 make : "Chevy",
 year : "2022",
 model : "Malibu",
 fuel : 0,
 started : false,

 start: function(){
 this.started = true;
 },

 stop: function(){
 this.started = false;
 },

 drive: function(){
 if(this.fuel > 0){
 if(this.started){
 for(let i = 0; i < this.fuel; i++){
 console.log(`Enjoying the drive in my ${this.make} --${this.model}`);
 console.log(`Fuel before deduction ${this.fuel}`);
 this.fuel = this.fuel - 1;
 console.log(`Fuel after drive = ${this.fuel}`);
 }
 }else{
 console.log(`You need to start the car to be able to drive`);
 this.stop();
 }
 }else{
 console.log("You need to fuel the car to be able to dirve");
 this.stop();
 }
 },

 addFuel: function(amount){
 this.fuel += amount;

 console.log(`Fuel Added ${this.fuel}`);
 }
};

car.drive();

car.addFuel(10);

car.drive();

car.start();

car.drive();
almost 4 years ago · Santiago Trujillo
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!