# After writing the function I am stuck on how to call the function.
> window.addEventListener("keydown",function(e){
if ((e.keycode==37)||(e.keycode==39)){
myFunction(e.key);
> function myFunction(s){
if (s =="ArrowLeft"){
let objectLR = object.style.left;
let objectPx = objectLR.slice(-2);
objectLR = objectLR.Replace(objectPx, " ");
objectLR = parseFloat(objectLR)- 10;
objectLR+= "px";
object.style.left = objectLR;
}
}
I'm not sure what you really want to do. Anyway, if you add an event listener to window, the event will trigger every time your event happens on your window (screen). In your example, myFunciton will be invoked every time you click arrow left or arrow right.
I found you have used keycode instead of keyCode, that is the reason your myFunction doesn't be invoked. But 'keyCode' is deprecated. You should try like that :
Additionally, always used === operator for comparison in javascript.