I'm trying to determine if a button is clickable based on certain requirements, but I can't seem to get the initial function to work.
Within this object array, each object represents a button with specific requirements. For example, the "story" button requires 10 ideas, denoted by story.ideaReq = 10
. To access "grana", you need to have at least 1 story, specified as grana.storyReq = 1
.
The desired output of my code should be:
story ideaReq 10
which translates to:
story.name = story,
req.name+'Req' = ideaReq and
story['ideaReq'] = 10
However, what I'm currently getting is:
story ideaReq undefined
Although console.log(story.ideaReq)
works perfectly fine, I need the ability to call this function for multiple objects beyond those mentioned above.
What am I overlooking?
const numbers = [
time = {
'name': 'time',
'in': 0,
'val': 0
},
idea = {
'name': 'idea',
'in': 0,
'val': 10,
'time': 1
},
story = {
'name': 'story',
'in': 0,
'val': 1,
'time': 4,
'ideaReq': 10
},
grana = {
'name': 'grana',
'in': 0,
'val': 1,
'time': 1,
'storyReq': 1
}
];
var checkButton = (button, req) => {
let name = button.name,
prop = req.name + 'Req';
console.log(name, prop, name['prop']);
}
checkButton(story, idea);