2

做类似的事情:

speak('Hello. Today is " + month + "/" + day + "/" + year + ", " + hours + ":" + minutes + ". I have couple suggestions of what to do today...Wanna go to the movies? Play some games? Go out to eat? Need anything else?')

当它写下它们时,它字面意思是" + month + "/" + day + "/" + year + ", " + hours + ":" + minutes + "

speak('')是另一个脚本定义的函数。是否可以将变量放入其中?

4

2 回答 2

3

这是因为单引号和双引号之间的交替。您想选择一个并始终如一地使用它。两种风格都是允许的(所有单打或双打),而且都不是首选,所以这是你的选择。

于 2013-05-16T19:28:06.550 回答
0

JavaScript 允许使用'single quotes'and"double quotes"来表示字符串的开始和结束。但是,您不能混合和匹配它们。即,'this will cause an error"

因此,您需要将程序文本更改为:

speak('Hello. Today is ' + month + '/' + day + '/' + year + ', ' + hours + ':' + minutes + '. I have couple suggestions of what to do today...Wanna go to the movies? Play some games? Go out to eat? Need anything else?')

或者:

speak("Hello. Today is " + month + "/" + day + "/" + year + ", " + hours + ":" + minutes + ". I have couple suggestions of what to do today...Wanna go to the movies? Play some games? Go out to eat? Need anything else?")
于 2013-05-16T19:30:33.500 回答