Javascript语法错误意外标记非法

发布于 2024-12-22 14:38:54 字数 938 浏览 0 评论 0原文

function queue_instructions(){
        var input_message = "Commands
    w?  Shows whos on the waitlist
    w+  Adds yourself to the waitlist
    w-  Removes yourself from the waitlist
    w++  Moves yourself down one spot on the waitlist
    -mods  Shows a list of available moderators
    -plays  Shows how many songs each DJ has played
    -promote  Requests a vote from everyone for you to be moved to 1st on the list
    -pull [#]  Requests a vote from everyone to pull that DJ off the booth  Number of DJ is     what number spot he is on the booth  Numbers read from left to right
    -remove [#]  Removes that number DJ from the waitlist  Must be a moderator
    -votekick [username]  Requests a vote from everyone to kick the user
     Type -help [command] for more info on a command (ie. -help w?)";
        deliver_chat(input_message);

我在 Google Chrome 上的 Javascript 控制台上收到语法错误意外 toke 非法。有什么想法吗?

function queue_instructions(){
        var input_message = "Commands
    w?  Shows whos on the waitlist
    w+  Adds yourself to the waitlist
    w-  Removes yourself from the waitlist
    w++  Moves yourself down one spot on the waitlist
    -mods  Shows a list of available moderators
    -plays  Shows how many songs each DJ has played
    -promote  Requests a vote from everyone for you to be moved to 1st on the list
    -pull [#]  Requests a vote from everyone to pull that DJ off the booth  Number of DJ is     what number spot he is on the booth  Numbers read from left to right
    -remove [#]  Removes that number DJ from the waitlist  Must be a moderator
    -votekick [username]  Requests a vote from everyone to kick the user
     Type -help [command] for more info on a command (ie. -help w?)";
        deliver_chat(input_message);

I get a syntax error unexpected toke illegal on my Javascript console on Google chrome. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

○愚か者の日 2024-12-29 14:38:54

您必须关闭每行上的这些引号,并使用 + 连接到下一行:

var input_message = "Commands " + 
    "w?  Shows whos on the waitlist " + 
    "w+  Adds yourself to the waitlist " + 

依此类推

您是否希望在每行中插入换行符?如果是这样,您可以使用 \n

var input_message = "Commands\n" + 
    "w?  Shows whos on the waitlist\n" + 
    "w+  Adds yourself to the waitlist\n" + 

You have to close those quotes on each line, and concatenate with + to the next line:

var input_message = "Commands " + 
    "w?  Shows whos on the waitlist " + 
    "w+  Adds yourself to the waitlist " + 

and so on

Did you want line breaks to be inserted with each line? If so, you can use \n:

var input_message = "Commands\n" + 
    "w?  Shows whos on the waitlist\n" + 
    "w+  Adds yourself to the waitlist\n" + 
故乡的云 2024-12-29 14:38:54

当您将字符串拆分为多行时,您需要像这样用 + 连接它

var input_message = "Commands"+
"w?  Shows whos on the waitlist"+
"w+  Adds yourself to the waitlist"+
"w-  Removes yourself from the waitlist"+
"w++  Moves yourself down one spot on the waitlist"+
"-mods  Shows a list of available moderators"+
"-plays  Shows how many songs each DJ has played"+;

而且在您的代码中,我没有找到它的右大括号 }功能。

function queue_instructions()
{
     //Stuff here.
}

你需要包含它。

When you split a string over multiple lines, you need to concatenate it with + like this

var input_message = "Commands"+
"w?  Shows whos on the waitlist"+
"w+  Adds yourself to the waitlist"+
"w-  Removes yourself from the waitlist"+
"w++  Moves yourself down one spot on the waitlist"+
"-mods  Shows a list of available moderators"+
"-plays  Shows how many songs each DJ has played"+;

And also in your code, I don't find the closing curly brace } of that function.

function queue_instructions()
{
     //Stuff here.
}

you need to include it.

真心难拥有 2024-12-29 14:38:54

你的语法不正确。您需要将整个字符串放在一行中,或者关闭每行中的引号,并使用 + 将下一行与其连接。

Your syntax is incorrect. You'll need to either put the whole string in one line OR close the quotes in each line a do a + to concat the next line with it.

零崎曲识 2024-12-29 14:38:54

或者你这样做:

var input_message = [
    "Commands",
    "w?  Shows whos on the waitlist",
    "w+  Adds yourself to the waitlist",
    "w-  Removes yourself from the waitlist",
    "w++  Moves yourself down one spot on the waitlist",
    "-mods  Shows a list of available moderators",
    "-plays  Shows how many songs each DJ has played",
    "-promote  Requests a vote from everyone for you to be moved to 1st on the list",
    "-pull [#]  Requests a vote from everyone to pull that DJ off the booth  Number of DJ is what number spot he is on the booth  Numbers read from left to right",
    "-remove [#]  Removes that number DJ from the waitlist  Must be a moderator",
    "-votekick [username]  Requests a vote from everyone to kick the user",
    "Type -help [command] for more info on a command (ie. -help w?)"
].join("\n");

Or you do like this:

var input_message = [
    "Commands",
    "w?  Shows whos on the waitlist",
    "w+  Adds yourself to the waitlist",
    "w-  Removes yourself from the waitlist",
    "w++  Moves yourself down one spot on the waitlist",
    "-mods  Shows a list of available moderators",
    "-plays  Shows how many songs each DJ has played",
    "-promote  Requests a vote from everyone for you to be moved to 1st on the list",
    "-pull [#]  Requests a vote from everyone to pull that DJ off the booth  Number of DJ is what number spot he is on the booth  Numbers read from left to right",
    "-remove [#]  Removes that number DJ from the waitlist  Must be a moderator",
    "-votekick [username]  Requests a vote from everyone to kick the user",
    "Type -help [command] for more info on a command (ie. -help w?)"
].join("\n");
蛮可爱 2024-12-29 14:38:54

我注意到没有人建议转义行结尾:

var multiStr = "This is the first line \
    This is the second line \
    This is more...";

请注意,行结尾包含在此字符串中...

http ://davidwalsh.name/multiline-javascript-strings

I notice no-one has suggested escaping the line-ending:

var multiStr = "This is the first line \
    This is the second line \
    This is more...";

Note that the line endings are included in this string…

http://davidwalsh.name/multiline-javascript-strings

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文