Copy the class instantiation, method call, and console.log() statements below into main.js


#1

I copied the given code like it said and I got this error message:
/home/ccuser/workspace/learn-javascript-classes-classes-introduction/main.js:13
const halley = new Dog(‘Halley’);
^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

here’s my code:
‘’’
class Dog {
constructor(name) {
this._name = name;
this._behavior = 0;
}

get name() {
return this._name;
}
get behavior() {
return this._behavior;
}

const halley = new Dog(‘Halley’);
console.log(halley.name); // Print name value to console
console.log(halley.behavior); // Print behavior value to console
halley.incrementBehavior(); // Add one to behavior
console.log(halley.name); // Print name value to console
console.log(halley.behavior); // Print behavior value to console

incrementBehavior() {
this._behavior ++;
}
}
‘’’


#2

class instantiation should happen after declaring class. The class declaration ends here:

incrementBehavior() {
this._behavior ++;
}
} // this closes the class declaration
``