Building Object-Oriented Program Help

I am confused as to why the error states it is expecting something different than function at this part " // Task 3: Code an intern object, run methods
function intern() { "

// Task 1: Code a Person class
class Person {
    constructor(name = Tom, age = 20, engergy = 100) {
        this.name = name;
        this.age = age;
        this.energy = energy;
    }
    sleep() {
        this.energy += 10
    }
    doSomethingFun() { this.energy -= 10 }
}
  // Task 2: Code a Worker class
  class Worker extends Person {
    constructor(xp = 0, hourlyWage = 10, name, age, energy) {
        super(name, age, energy);
        this.xp = xp;
        this.hourlyWage = this.hourlyWage;
    }
        goToWork() { this.exp += 10 }
 // Task 3: Code an intern object, run methods
function intern() {
    {var intern = new worker(0, 10, 'Bob', 21, 110)
    intern.goToWork();
    return intern;
}
    constructor(name = "Tom", age = 20, energy = 100, xp = 0, hourlyWage = 10); {
    super(name, age, energy);
    this.xp = xp;
    this.hourlyWage = hourlyWage;
  }
    goToWork(); {
    this.xp += 10;
  }
}
// Task 4: Code a manager object, methods
function manager() {
    var manager = new Worker(100, 30, 'Alice', 30, 120);
    manager.doSomethingFun();
}
1 Like

You seem to be missing a closing } for your Worker class, because right after the goToWork() {this.exp += 10;}, you start a function declaration.

But then for some reason you have a call to a constructor function that is not defined anywhere. Also, you have a call to a super function that is not defined anywhere.

It is not clear what you are trying to do here.

Something that would help you and others reviewing your code would be to try and properly indent the code. This helps us see what parts you want to be “inside” other parts.

I feel like I could fix this if I understood how to read the output log. Here is what I am trying to do:
Task 1: Code a Person class
Code a Person class, with three parameters in the constructor: name, age, and energy.

Set the default parameters in the Person class as follows:

name = “Tom”

age = 20

energy = 100

Code two methods in the Person class. Name those methods sleep() and doSomethingFun().

The sleep() method should take the exisiting energy level and increase it by 10.

The doSomethingFun() method should take the exisiting energy level and decrease it by 10.

Task 2: Code a Worker class
Code a sub-class, inheriting from the Person class, and name it Worker.

The Worker class has two additional parameters in the constructor:

  • xp (for "experience points)
  • hourlyWage.

These properties are set to the following default values:

xp = 0

hourlyWage = 10

The Worker class has all the parameters and methods of its super-class.

Additionally, it has the goToWork() method, which, whenever it’s run, increases the value of the xp property by 10.

Task 3: Code an 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.

Here is my code:
// Task 1: Code a Person class
class Person {
constructor(name = Tom, age = 20, engergy = 100) {
this.name = name;
this.age = age;
this.energy = energy;
}
sleep() {
this.energy += 10
}
doSomethingFun() { this.energy -= 10 }
}
// Task 2: Code a Worker class
class Worker extends Person {
constructor(xp = 0, hourlyWage = 10, name, age, energy) {
super(name, age, energy);
this.xp = xp;
this.hourlyWage = this.hourlyWage;
}
goToWork() { this.exp += 10 }
}
// Task 3: Code an intern object, run methods
function intern() {
{
var intern = new worker(0, 10, Bob, 21, 110)
intern.goToWork();
return intern;
}
}

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

Here is the OUTPUT in Visual Basic:

[Running] node “/home/coder/project/learn/tempCodeRunnerFile.js”
/home/coder/project/learn/tempCodeRunnerFile.js:2
(name, age, energy);

SyntaxError: Unexpected end of input
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47

[Done] exited with code=1 in 0.067 seconds

[Running] node “/home/coder/project/learn/ooprogramming.js”

[Done] exited with code=0 in 0.065 seconds

Help please.

Without being able to see what tempCodeRunnerFile.js looks like it is hard to recreate the errors you are seeing.

I did notice several problems when your code when I attempted to run any of the functions (something you should be testing on your own).

For example, I see a typo here:

engergy = 100

You have a class named Worker but in your intern function you attempt to call new worker. Also, in this call you reference Bob but there is no variable named Bob defined anywhere. I assume you meant to pass the string 'Bob' but you did not wrap it with quotes. You did something similar in the manager function.

I am very new to this a taking a Coursera course on Java Script. I would love to understand where I am going wrong. It isn’t that I am not attempting to do it myself. I don’t understand where I am going wrong and what questions I need to ask to get back on track. I got the misspelling, the closed bracket, and the indention pieces you mentioned. Thank you for those pieces of feedback. In my last entry, I gave you everything I have. So, when you say you can’t see tempCodeRunnerFile.js, neither can I.

What would I see to know I was on track and my code was working so far? If I do Task 1 and save and run it should I show No Problems? What should Output show?

Sounds like you should seek support from Courera or see if they have a forum where you can ask questions.