Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

412
Views
tratando de incluir una secuencia de comandos en pug y llamar a una función desde la secuencia de comandos, obteniendo un error de "token inesperado"

Tengo una plantilla pug donde quiero llamar a una función con algunas variables pasadas desde el punto final que representa la página:

 doctype html html head title= title link(rel='stylesheet', href='/stylesheets/style.css') body button(type = 'button' onclick='play(#{x},#{y})') script(type='text/javascript' src='../public/javascripts/play.js')

Aquí está play.js :

 const play = function(x,y){ console.log(x+y); }

Cuando cargo la página, me sale este error:

 Uncaught SyntaxError: Unexpected token ':' play.js:1

¿Cómo puedo hacer que pug incluya el script correctamente para poder llamar a la función con un clic de botón?

EDITAR: aquí está el HTML renderizado:

 <!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" href="/stylesheets/style.css"> </head> <body> <button type="button" onclick="play(#{x},#{y})"></button><script type="text/javascript" src="../public/javascripts/play.js"></script> </body> </html>

EDITAR 2:

Cambié la interpolación a

 onclick=`play(${x},${y})`

y esto se traduce como:

 onclick="play(2,3)"

cuáles son los valores que se pasaron desde el punto final, pero sigo recibiendo el error de unexpected token .

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!