Today in school, I learned about objects and how a function inside an object is actually called a method. In my method, I have an array and I'm trying to change a global variable to display a different location in the console.log. However, all I keep getting is undefined in the last console.log. I'm attempting to change the global variable, var myLocation = 0, to output a different myLocation inside the getLocation method.
var myLocation = 0
var worker = {
realName: "Willson",
title: "Assistant Maintenance Supervisor",
maintenance: true,
vehicals: ["2008 Dodge Caliber SRT-4", "2012 Jeep Wrangler Unlimited" ],
getLocation: function () {
myLocation [0] = "Villas at Sunrise Mountain";
myLocation [1] = "Reno Villas";
myLocation [2] = "lost";
myLocation [3] = "back home";
}
};
console.log(worker.realName + " is a " + worker.title + " and drives a " + worker.vehicals[1] + " to work.");
var destination = {
property: ["Villas at Sunrise Mountain", "Reno Villas", "lost", "back home"]
};
console.log ("He sold his " + worker.vehicals[0] + "." + " Today he is working at " + worker.getLocation.myLocation);