Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript';t显示代码的结果_Javascript_Html_Libreoffice_Bluefish - Fatal编程技术网

JavaScript';t显示代码的结果

JavaScript';t显示代码的结果,javascript,html,libreoffice,bluefish,Javascript,Html,Libreoffice,Bluefish,我尝试根据我对MDN源代码的改编创建一个简单的JavaScript文件 我的JavaScript代码(loughshore_clubs.js)如下 <!-- var Club = “Ballinderry” ; function ClubType(name){ if (name == “Ardboe”){ return name ; } else{ return “I'm not from “+ name + “.”; } } var clubs {myClub: ClubType(“

我尝试根据我对MDN源代码的改编创建一个简单的JavaScript文件

我的JavaScript代码(loughshore_clubs.js)如下

<!--
var Club = “Ballinderry” ;

function ClubType(name){
if (name == “Ardboe”){
return name ;
} else{
 return “I'm not from “+ name + “.”;
}
}
var clubs {myClub: ClubType(“Ardboe”), club2: ClubType(Club), 
club3:  
ClubType(“Moortown”)}

console.log(clubs.myClub); //Ardboe
console.log(clubs.club2); //Ballinderry
console.log(clubs.club3); //Moortown

/-->

HTML源代码(test.HTML)是



怎么了?我意识到的一件事是,我应该避免使用LibreOffice保存HTML文件,而坚持使用Bluefish。(这是我在Mac o/s X Yosemite上看到的)

删除脚本的第一行和最后一行。HTML注释标记在
.js
文件中毫无意义

然后将每个
字符替换为正确的

您还缺少
俱乐部
{
之间的
=
,此处:
var俱乐部{myClub:…

进行这些更改后,您应该:

var Club = "Ballinderry";

function ClubType(name){
    if (name == "Ardboe") {
        return name;
    } else {
        return "I'm not from " + name + ".";
    }
}

var clubs = {
  myClub: ClubType("Ardboe"),
  club2: ClubType(Club), 
  club3: ClubType("Moortown")
};

console.log(clubs.myClub); //Ardboe
console.log(clubs.club2); //Ballinderry
console.log(clubs.club3); //Moortown
这应该起作用:

var Club = "Ballinderry" ;

function ClubType(name){
if (name == "Ardboe"){
return name ;
} else{
 return "I\'m not from "+ name + ".";
}
}
var clubs = {
  myClub: ClubType("Ardboe"),
   club2: ClubType(Club),
   club3: ClubType("Moortown")
 };

console.log(clubs.myClub); //Ardboe
console.log(clubs.club2); //Ballinderry
console.log(clubs.club3); //Moortown
你是对的,你应该停止使用LibreOffice保存代码,因为它将你所有的
更改为
。我建议使用

并且在声明
clubs
变量时没有
=

再一次,获取atom,然后下载
linter
包并使用
JShint
。这应该会让你养成编写好代码的习惯。我自己使用它。如果你需要更多帮助,请发推给我,我两个月前就开始了,我刚刚完成了我的第一个Node.js应用程序的后端


编辑:另一个答案击败了我,他应该获得投票权。:p

为什么你的js文件被注释掉了?你的JavaScript充满了语法错误。还有,顶部和底部的HTML风格的注释是什么?例如,你在
var clubs
var clubs={key:value}之后缺少一个
=
我希望你知道为什么你永远不应该使用像LibreOffice这样的文字处理软件来编写任何类型的代码。这些类型的软件不会以纯文本形式保存你的文件,它们会对你的文件应用各种格式,任何代码解析器/编译器都会失败。你也不必使用Bluefish,总有其他选择在这里写代码。
var Club = "Ballinderry" ;

function ClubType(name){
if (name == "Ardboe"){
return name ;
} else{
 return "I\'m not from "+ name + ".";
}
}
var clubs = {
  myClub: ClubType("Ardboe"),
   club2: ClubType(Club),
   club3: ClubType("Moortown")
 };

console.log(clubs.myClub); //Ardboe
console.log(clubs.club2); //Ballinderry
console.log(clubs.club3); //Moortown