Unexpected token function

Unexpected token function


I am doing the Simon Game (last project of frontend). I’ve needed a function that waits for user answer. So, I made this function:

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));

And I used it on my start function (the Simon Game engine):

async function start() {
  var audio;
  isRunning = true;
  addSound(); // add new audio to sequence
  while(ON) {
    playSequence(0, audio);
    // wait 7s for user answer
    await sleep(7000); 
    if(isAnswerCorrect()) {    
    } else {
      count = 0;
      // answer incorrect: play corresponding audio
      var audio = playAudio(5);
      setTimeout(stopAudio(audio), 1000);
    aux = 0;

But this function is causing the following error: Unexpected token function.
What does that mean?

My code is here: http://codepen.io/raulfm/pen/qmdwpb?editors=1010


The await keyword is fairly new syntax, so chrome may not yet support it. If you pre-compile with Babel does that do you any good?


How can I use Babel with Codepen? I went to https://babeljs.io/ and I pasted my start() function there. But I wasn’t able to copy the “browser-compatible JavaScript”. Am I understanding what Babel is?