Intended changes occur only after clicking a button a second time

When I click the button, the intention is for the image to be changed and the image resolution to be shown to me through the “console.log”, however, this only happens when I click it a second time. On the first click, the original sprite image disappears, and the values ​​of the global variable to store the resolution remain at the value I defined. The other events, without javascript, are only to adjust the position and size of the image on the screen, based on the image resolution. Attached is an image of the events and the code.