[英]Why doesn't JSFiddle output results for this code
I have been using the Firebug javascript console to test short scripts. 我一直在使用Firebug javascript控制台来测试短脚本。 Several people have suggested using JSFiddle instead.
有人建议使用JSFiddle。 The problem is I can't seem to figure out how to do this.
问题是我似乎无法弄清楚如何做到这一点。 I enter my code in the js panel and hit run but nothing happens.
我在js面板中输入我的代码并点击运行但没有任何反应。 I am assuming something should output to results?
我假设某些东西应输出到结果? I tried different settings, reading the JSFiddle documentation, reading other questions posted on Stackoverflow, but I can't figure it out.
我尝试了不同的设置,阅读JSFiddle文档,阅读Stackoverflow上发布的其他问题,但我无法弄清楚。 It seems like it should be so simple.
看起来应该这么简单。 Maybe it only works if I call it from HTML?
也许只有从HTML中调用它才有效? http://jsfiddle.net/nngrey/QgxCn/ (I had to include my code to reference the link to JSFiddle.)
http://jsfiddle.net/nngrey/QgxCn/ (我必须包含我的代码来引用JSFiddle的链接。)
function Palindrome(str) {
str = str.split("");
for (var i = 0; i < str.length; i++) {
if (str[i] === " ") {
str.splice(i, 1);
}
}
revStr = str.reverse().join("");
str = str.join("");
if (revStr === str) {
return true;
} else {
return false;
}
return str;
}
str = "dont nod";
Palindrome(str);
You can use this jsFiddle to output stuff with console.log. 您可以使用此jsFiddle通过console.log输出内容。 Same idea as alert(), but without a popup you have to close.
与alert()相同的想法,但没有弹出窗口,你必须关闭。 Thanks to Wayne Koort .
感谢Wayne Koort 。
http://jsfiddle.net/TEHLb/ http://jsfiddle.net/TEHLb/
var consoleLine = "<p class=\"console-line\"></p>";
console = {
log: function (text) {
$("#console-log").append($(consoleLine).html(text));
}
};
var myVar = "foo";
console.log('Your variable has the value ' + myVar);
Without any html to display your answer you can alert it to see the results. 没有任何HTML显示您的答案,您可以提醒它以查看结果。
function Palindrome(str) {
str = str.split("");
for (var i = 0; i < str.length; i++) {
if (str[i] === " ") {
str.splice(i, 1);
}
}
revStr = str.reverse().join("");
str = str.join("");
if (revStr === str) {
return true;
} else {
return false;
}
return str;
}
str = "dont nod";
alert(Palindrome(str));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.