I am trying out JavaScript objects, and I'm just stuck on why I am getting a TypeError in my code.
var marvelFunFact = {
captainMarvel: [
{
info: "Did you know that info 1",
imageUrl: "url.com/image1.jpg"
},
{
info: "Did you know that info 2",
imageUrl: "url.com/image2.jpg"
},
{
info: "Did you know that info 3",
imageUrl: "url.com/image3.jpg"
}
],
lastName: "Doe",
};
var marvelFunFactContext = "captainMarvel";
var rand = marvelFunFact.marvelFunFactContext[Math.floor(Math.random() * marvelFunFact.length)].info;
The error that appears is "TypeError: marvelFunFact.marvelFunFactContext is undefined". I am only a beginner, don't judge, this is probably just a simple fix :/