0

here is my code, I cannot work out why the browser is telling me that }); is an unexpected token in my code..

script
  var canvas = document.getElementById('canvas');

  canvas.width = canvas.clientWidth;
  canvas.height = canvas.clientHeight;

  var c =  canvas.getContext('2d');

  var width = canvas.width;
  var height = canvas.height;

  var controller = new Leap.Controller();

  controller.on( 'frame' , function(frame){
    c.clearRect(0, 0, width, height);
    var numberOfFingers = frame.fingers.length;
    c.font = "200px Arial";
    c.textAlign = 'center';
    c.textBaseline = 'middle';
    c.fillText( numberOfFingers , width/2 , height/2 );
  });
  controller.connect();

and here is the syntax error that chrome is throwing up, its probably very simple but I can't see whats wrong!

 SyntaxError: /Users/plimb/Desktop/motion-therapy/views/hand.jade:33
      31|       c.textBaseline = 'middle';
      32|       c.fillText( numberOfFingers , width/2 , height/2 );
    > 33|     });
      34|     controller.connect();
      35| 



Unexpected token ;
      at Function (<anonymous>)
      at assertExpression (/Users/plimb/Desktop/motion-      therapy/node_modules/jade/lib/lexer.js:31:3)
    at Object.Lexer.attrs (/Users/plimb/Desktop/motion-therapy/node_modules/jade/lib/lexer.js:648:20)
    at Object.Lexer.next (/Users/plimb/Desktop/motion-therapy/node_modules/jade/lib/lexer.js:868:15)
    at Object.Lexer.lookahead (/Users/plimb/Desktop/motion-therapy/node_modules/jade/lib/lexer.js:114:46)
    at Parser.lookahead (/Users/plimb/Desktop/motion-therapy/node_modules/jade/lib/parser.js:100:23)
    at Parser.peek (/Users/plimb/Desktop/motion-therapy/node_modules/jade/lib/parser.js:77:17)
    at Parser.tag (/Users/plimb/Desktop/motion-therapy/node_modules/jade/lib/parser.js:733:22)
    at Parser.parseTag (/Users/plimb/Desktop/motion-therapy/node_modules/jade/lib/parser.js:719:17)
    at Parser.parseExpr (/Users/plimb/Desktop/motion-therapy/node_modules/jade/lib/parser.js:188:21)
PravinS
  • 2,640
  • 3
  • 21
  • 25
plimbs
  • 1,459
  • 2
  • 10
  • 12

1 Answers1

2

Jade is trying to interpret your nesting, I would avoid using jade to compile JavaScript blocks. This person had a similar problem

have a look at serving static content with nodejs

app.use(express.static(__dirname + '/js');
Community
  • 1
  • 1
actual_kangaroo
  • 5,971
  • 2
  • 31
  • 45
  • Hi, I put the code into a js file and then included it in the jade script(src='/js/hand.js'). It works fine now and it is a much cleaner way of doing things! thanks for your help. I'm new to node.js! – plimbs Mar 31 '14 at 12:54
  • thanks for accepting, have fun with node and the motion controller! – actual_kangaroo Mar 31 '14 at 12:58