window.innerWidth not working but works when i turn on inspect

window.innerWidth is not working as should do, I need to show an alert message when the window width is less than 480 but it shows nothing but works when I turn on inspect, and here is my code

function updateMessage() {

    if (window.innerWidth < 480) {
        alert("Hello! I am an alert box!!");
    };

  };

  window.addEventListener("load", updateMessage);
  window.addEventListener("resize", updateMessage);