Function KeyPressed

Hi !
I’m quite new in javascript and I tried to program a Flappy bird with the coding train video.
I did a function named KeyPressed

function KeyPressed () {
  if (key == "") {
    console.log("SPACE");
  }
}

But it’s not working and I don’t see anything appear when I press space in the console. Can you help me with it ? Thanks !

1 Like

"" is an empty String. Use " " (or ' ') instead for the space character. :wink:

P.S.: Edit & format your posted code. :spiral_notepad:

1 Like

Yeah ! It’s working. Thanks a lot !

also it should be

function setup() {

}

function draw() {
  
}

function keyPressed() {
  print("keyPressed "+key+" keyCode "+keyCode);
  if ( key == ' ' ) console.log("[space]"); 
}

and we see it ?
in browser / inspect / Console

1 Like

Thanks a lot for the fast answer !