title: JavaScript - How can I use an alert when an image has reached the top of the page?
body: <p>i'm new into programming and I was trying to make an sort of race with a rocket. The rocket has to reach the top of the page and when it has reached the top of the page I want an alert to come out(?). What is the best of way doing this? Thanks in advance!</p>
  
  <p>Ive edited my post, I used the "if" just under my function downpressed.. But it doesnt work.</p>
  
  <pre><code>    function leftArrowPressed() {
          var element = document.getElementById("image1");
          element.style.left = parseInt(element.style.left) - 5 + 'px';
          }
  
          function rightArrowPressed() {
          var element = document.getElementById("image1");
          element.style.left = parseInt(element.style.left) + 5 + 'px';
  
          }
  
          function upArrowPressed() {
          var element = document.getElementById("image1");
          element.style.top = parseInt(element.style.top) - 5 + 'px';
          }
  
          function downArrowPressed() {
          var element = document.getElementById("image1");
          element.style.top = parseInt(element.style.top) + 5 + 'px';
          }
  
  
  
  
          function moveSelection(evt) {
  
              if(parseInt(element.style.top)==0)
              {
                  alert("some text there");
              }
              switch (evt.keyCode) {
                  case 37:
                  leftArrowPressed();
                  break;
                  case 39:
                  rightArrowPressed();
                  break;
                  case 38:
                  upArrowPressed();
                  break;
                  case 40:
                  downArrowPressed();
                  break;
                  }
              };
  
      function docReady()
      {
  
        window.addEventListener('keydown', moveSelection);
      }
  </code></pre>