i am a noob to javascript. I how have tried to access my url variable in another block but it either says Uncaught ReferenceError: value is not defined or i can't access it when i define it. thanks in advance. #i have also defined it in another scope.
const myJson = { "images":[
{"scissors": {"url":"images/icon-scissors.svg"}},
{"paper": {"url":"images/icon-paper.svg"}},
{"rock": {"url":"images/icon-rock.svg"}}
]};
for(let key in e){
value = e[key];
url = value.url;
}
if(randChoice.scissors){
let url = value.url;
console.log(url[0])
}
//the other place i defined it
const myJson = { "images":[
{"scissors": {"url":"images/icon-scissors.svg"}},
{"paper": {"url":"images/icon-paper.svg"}},
{"rock": {"url":"images/icon-rock.svg"}}
]};
const selected = myJson.images.find((elem)=> {
for(let key in elem){
if(triggerType === key) {
const value = elem[key]
url = value.url
selectedChoiceImg.src = url
}else{
return
}
}
})
// json file
{ "images":[
{"scissors": {"url":"images/icon-scissors.svg"}},
{"paper": {"url":"images/icon-paper.svg"}},
{"rock": {"url":"images/icon-rock.svg"}}
]}