Unable to change variable by function

I can’t figure out why my function getID() isn’t changing the galleryID variable.
Any help appreciated!

var img;
var gallery = {0: "CIBf-QSFMZD", 1: "CFfihZ0BxQo", 2: "CDUNuwvgB7N", 3: "CByDTh8gUWa", 4: "CB3i7NoA-IK", 5: "CKSEJG9rlJn", 6: "CEHrD8yAFXn", 7: "CIY6OZ-FGJB", 8: "B-12Va2DQ96", 9: "CB3e-QHAx5e", 10: "CI29bFllEBm", 11: "B1enhruHg9i"};
var galleryID;
function on(ima) {
  img = ima.id;
  document.getElementById("instagram-embed").src = "https://www.instagram.com/p/" + img + "/embed?utm_source=ig_embedembed/captioned/";
  document.getElementById("overlay").style.display = "block";
  document.getElementbyId("container").style.backgroundColor = "black";
  document.getElementById("container").style.zIndex = "2";
  getID();
}

Everything seems to work fine aside from the function below

function getID() {
var i = 0;
while(!(img == gallery[i])){
i++;
}
galleryID = i;
}

The value of galleryID just won’t change from undefined.
I’ve checked the equality comparison statement separately and it seems to be working ok, giving the right true and false outputs.

Thanks for any help!

7 thoughts on “Unable to change variable by function”

  1. 923936 812231 There are some fascinating points in time in this write-up but I dont know if I see all of them center to heart. There is some validity but I will take hold opinion until I appear into it further. Great article , thanks and we want more! Added to FeedBurner as well 362674

    Reply