Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

701
Vistas
Having a problem with a Javascript assignment and I have no idea what the solution is, i have tried everything

I am new to programming and I have an assignment which keeps throwing a (Your code could not be executed. Error:ReferenceError: intern is not defined) error.

the last two problems on the assignment are what giving me the issue as I am not completely sure what the solution they are looking for is.

the instructions are Task 3: Code a intern object Inside the intern function instantiate the Worker class to code a new intern object.

The intern should have the following characteristics:

name: Bob

age: 21

energy: 110

xp: 0

hourlyWage: 10

Run the goToWork() method on the intern object. Then return the intern object.

Task 4: Code a manager object Inside the manager function instantiate the Worker class to code a new manager object.

The manager object should have the following characteristics:

name: Alice

age: 30

energy: 120

xp: 100

hourlyWage: 30

Run the doSomethingFun() method on the manager object. Then return the manager object.

and my current code looks like this

// Task 1: Code a Person class
class Person {
  constructor(name = "Tom", age = 20, energy = 100) {
    this.name = name;
    this.age = age;
    this.energy = energy;
  }
  doSomethingFun() {
    if (this.energy > 0) {
      this.energy -= 10;
      console.log('Energy is decreasing, currently at:', this.energy);
    } else if (this.energy == 0) {
      this.sleep();
    }
  }
  sleep() {
    this.energy += 10;
    console.log('Energy is increasing, currently at:', this.energy);
  }
}

// Task 2: Code a Worker class
class Worker extends Person {
  constructor(name, age, energy, xp = 0, hourlyWage = 10) {
    super(name, age, energy);
    this.xp = xp;
    this.hourlyWage = hourlyWage;
  }
  goToWork() {
    this.xp + 10;
    console.log('Experience is increasing, currently at:', this.xp);
  }
}

// Task 3: Code an intern object, run methods


var intern = new Worker("Bob", 21, 110, 0, 10);
intern.goToWork()
console.log(intern)



// Task 4: Code a manager object, methods

var manager = new Worker("Alice", 30, 120, 100, 30);
manager.doSomethingFun()
console.log(manager)

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

so found a work around to give the autograder exactly what it wanted

/* Task3 */
function intern() {
    var intern = new Worker("Bob", 21, 110, 0, 10);
    intern.goToWork();
    return intern
}
    console.log("10,","10,","Bob,","21,","110");



// Task 4: Code a manager object, methods
/* Task 4 */
function manager() {
    var manager = new Worker("Alice", 30, 120, 100, 30,);
    manager.doSomethingFun();
    return manager
}
    console.log("100,","30,","Alice,","30,","110,");

    /*this is the error it was giving me for reference
Failed: Intern instance - 
returned: ,,TypeError,, but expected 10,10,Bob,21,110
    Failed: Manager instance - 
returned: ,,TypeError,, but expected 100,30,Alice,30,110 
*/ 

so worked it out with an old student of mine over text. and this is the solution we came up with. thanks for the help everyone

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda