I want to check if some button is clickable according to some requirements but I can't even make the start of the function works.
I have this object array. Each object is a button and some of them have a requirement. Eg: for story to be clickable it need 10 ideas, so story.ideaReq = 10
. To get grana, you need to have 1 story, so grana.storyReq = 1
.
My code should return:
story ideaReq 10
that is:
story.name = story,
req.name+'Req' = ideaReq and
story['ideaReq'] = 10
But it returns:
story ideaReq undefined
If I console.log(story.ideaReq)
it works perfectly but I need to be able to call this function (as I'll end having more objects than those above).
What am I missing?
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);