I have a
var imgSrc = false;
dom.getElByTag('img')[0].onclick = function(){
//set src of image
changeBool(dom.getElByTag('img')[0]);
}
function changeBool(n){
if(n.src ===="file/path"){
imgSrc = true;
};
console.log(imgSrc);
So the problem is that imgSrc is only changed locally in changeBool so if I console.log imgSrc it will return false, regardless of where I put it (this is likely because the page has already loaded and decided that imgSrc is false before I set it to true with the onclick, and since javascript runs one line at a time it has run console.log(imgSrc) as false before I could even click the image.
So, I need to:
declare a boolean as false -> click an image, which sets boolean as true -> console.logging the boolean (and seeing true)
But what I am doing right now is: declare a boolean as false -> console.logging the boolean (and seeing false {because it hasn't been set to true yet} - > clicking an image and setting the boolean to true.
How can I fix this?