Javascript I';我试图制作一个将两个单词混合在一起的程序,但当我添加一个函数时,它就停止工作了

Javascript I';我试图制作一个将两个单词混合在一起的程序,但当我添加一个函数时,它就停止工作了,javascript,function,Javascript,Function,这是我的密码。 - var words=[“单词”、“另一个单词”、“最后一个单词”]; var wordsLast=[“后缀”、“更多”、“更多”] 函数textMasher()={ document.getElementById(“demo”).innerHTML=neem[Math.round(Math.random()*2)]; document.getElementById(“demo2”).innerHTML=neemLast[Math.round(Math.random()*2)

这是我的密码。

-
var words=[“单词”、“另一个单词”、“最后一个单词”];
var wordsLast=[“后缀”、“更多”、“更多”]
函数textMasher()={
document.getElementById(“demo”).innerHTML=neem[Math.round(Math.random()*2)];
document.getElementById(“demo2”).innerHTML=neemLast[Math.round(Math.random()*2)];
}
示例文本

函数名后面有一个=符号。下面是正确的代码:

function textMasher() { document.getElementById("demo").innerHTML = words[Math.round(Math.random()*2)]; document.getElementById("demo2").innerHTML = wordsLast[Math.round(Math.random()*2)]; } 函数textMasher(){ document.getElementById(“demo”).innerHTML=words[Math.round(Math.random()*2)]; document.getElementById(“demo2”).innerHTML=wordsLast[Math.round(Math.random()*2)]; }
函数名后面有一个=符号。下面是正确的代码:

function textMasher() { document.getElementById("demo").innerHTML = words[Math.round(Math.random()*2)]; document.getElementById("demo2").innerHTML = wordsLast[Math.round(Math.random()*2)]; } 函数textMasher(){ document.getElementById(“demo”).innerHTML=words[Math.round(Math.random()*2)]; document.getElementById(“demo2”).innerHTML=wordsLast[Math.round(Math.random()*2)]; }
问题出在这一行:

function textMasher() = {
此处不需要
=
。换成

function textMasher() {
请注意,错误消息告诉您问题在第19行。当您遇到这些类型的错误时,您应该从它所说的那一行开始,通过代码反向查找问题的原因。有一种技术就像您开始做的那样:删除一些代码,看看会发生什么。在本例中,错误消失了,因此下一步是将部分代码放回。例如,您可以只添加一个空函数:

<!DOCTYPE html>
<html>
<body>
<span id="demo"></span>
<span>-</span>
<span id="demo2"></span>
<script>
var words = ["Word", "Another Word", "One last word"];
var wordsLast = ["Suffix", "more", "and more"]
function textMasher() = {
}

</script>
<button type = "button" onclick =  textMasher()>sample text</button>
</body>
</html>

从这里,您可以查看函数声明的语法,并希望找到问题所在。

问题在这一行:

function textMasher() = {
此处不需要
=
。换成

function textMasher() {
请注意,错误消息告诉您问题在第19行。当您遇到这些类型的错误时,您应该从它所说的那一行开始,通过代码反向查找问题的原因。有一种技术就像您开始做的那样:删除一些代码,看看会发生什么。在本例中,错误消失了,因此下一步是将部分代码放回。例如,您可以只添加一个空函数:

<!DOCTYPE html>
<html>
<body>
<span id="demo"></span>
<span>-</span>
<span id="demo2"></span>
<script>
var words = ["Word", "Another Word", "One last word"];
var wordsLast = ["Suffix", "more", "and more"]
function textMasher() = {
}

</script>
<button type = "button" onclick =  textMasher()>sample text</button>
</body>
</html>

从那里,您可以查看函数声明的语法,并希望找到问题所在。

当您按照此处发布的方式运行代码时,是否会出现任何错误?如果是,它们是什么?{“message”:“Uncaught SyntaxError:意外标记“=”,“filename”:“,“lineno”:19,“colno”:23}请用错误消息回答您的问题,并指出导致错误的行。此外,在加载页面或单击按钮时是否会发生此错误。当您在此处发布代码时运行代码时是否会出现任何错误?如果是,它们是什么?{“message”:“Uncaught SyntaxError:意外标记“=”,“filename”:“,“lineno”:19,“colno”:23}请用错误消息回答您的问题,并指出导致错误的行。此外,在加载页面或单击按钮时是否会发生此错误。哦。我想这会比那困难得多。非常感谢。哦我想这会比那困难得多。非常感谢。