Multiple errors in your code:
if (greeting = undefined)
You are
assigning[
^] the value
undefined
to the
greeting
variable here. Instead, you should be
testing for equality[
^].
name = "Anonymous";
...
greeting = "Hello";
You have declared both
name
and
greeting
as
const[
^]. That means you cannot change their value. Any attempt to do so will result in an error.
Use
let[
^] to declare a variable which can be changed.
return "${greeting}, ${name}!";
You are returning the literal string
${greeting}, ${name}!
. You should be using
a template string[
^] instead. That means using back-ticks (
`) instead of quotes (
" or
') to start and end your string.
g = new Greeter("Hi")
Not technically an error, but you haven't declared the
g
variable anywhere. Use
let g = ...
instead.
g.greet()
You're not doing anything with the value returned from this method. You should either store it somewhere for later use, or display it to the user somehow.
In future, make sure you provide a complete and precise description of the error(s) you are trying to solve.