You can see the video tutorial from here if you wish:
If you test the code on your browser, you will see the alert box whenever you press one of the arrow keys. In our code, we have used switch case statement instead of if statement. If you want, then you can also use if statement. But I think switch case statement is more readable and easy way then if statement.