0

i'm a beginner in JavaScript and I've just learned about functions and arrays and I've a problem with the code below : First i had defined the next array:

let WorkerS = {
    Php : "Alexander",
    Python : "Vadim",
    Html : "Vladimir",
    JS : "Fyodor",
};

Then i defined this simple function:

    const Element = (Language) => {
    return WorkerS.Language
};

And when i call:

console.log(Element(Php));

it gives me an error:

ReferenceError: Php is not defined

, please help me to know where the error is:

1 Answers1

-1

Change your function to:

const Element = (Language) => {
  return WorkerS[Language];
};

and then change your call to

console.log(Element('Php')); //as you can see Php is a string
Kobe
  • 6,226
  • 1
  • 14
  • 35
arpitansu
  • 588
  • 4
  • 12