Objects in JavaScript

Objects in JavaScript
0.0 0

#1

Hi

Wandering if you can help

I am working through the freeCodeCamp JavaScript tutorials.

I keep getting this error:
Script snippet #1:18 Uncaught ReferenceError: objName is not defined
at showProps (:18:17)
at :23:13

Not too sure why?

var myCar = new Object();
myCar.make = “Ford”;
myCar.model = “Mustang”;
myCar.color;
console.log(myCar.make);
console.log(myCar.colour);

myCar[“year”] = 1969;
console.log(myCar[“model”]);

myCar[“Do I like?”] = “I hate my car.”;
console.log(myCar[“Do I like”]);

function showProps(obj, objname) {
var result ="";
for (var i in obj) {
if (obj.hasOwnProperty(i))
result += objName + “.” + i + “=” + obj[i] + “\n”
}
}
return result;
}
console.log(showProps(myCar, “myCar”))


#2

Off-topic: you are spelling color in both the American and British ways, so myCar.colour will be undefined.

On-topic: you have a second typo: objname is in all lowercase as a parameter, but in camelCase inside the function.


#3

Thanks for your help mate… A fresh pair of eyes was needed for sure :slight_smile: