[英]How Do You Make Your Entire OWN Language Coder? I Tried This.. (doesn't work)
I tried to make it all connect but nothing is working.. I am horrible at JavaScript.. It says that it is 'undefined'. 我试图使其全部连接,但没有任何效果。.我对JavaScript感到恐惧。.它说它是'undefined'。 I think it is defined..
我认为这是定义。
var convert = function (x) {
alert(dxc(x));
function dxc(m) {
stg(m.charAt(0));
}
function stg(d) {
if (d === "d") {
d = "p";
}
}
};
var conversion = prompt("What do you want to translate?");
convert(conversion);
Edit: This is just for the idea of the entire thing, I was no where near done.. 编辑:这只是整个事情的主意,我离完成还差得远。
You forgot to return
the values you want to return 您忘了
return
要return
的值
var convert = function(x) {
alert(dxc(x));
function dxc(m) {
return stg(m.charAt(0));
}
function stg(d) {
if (d === "d") {
d = "p";
}
return d;
}
};
var conversion = prompt("What do you want to translate?");
convert(conversion);
Your functions aren't returning anything. 您的函数没有返回任何东西。
Try: 尝试:
var convert = function (x) {
alert(dxc(x));
function dxc(m) {
return stg(m.charAt(0));
}
function stg(d) {
if (d === "d") {
d = "p";
}
return d;
}
};
d
is just a name that points to a value; d
只是一个指向值的名称; when you do d = "p"
, you're changing what d
points to, but you changed only d
; 当您执行
d = "p"
,您正在更改d
指向的内容,但仅更改了 d
; the source of d
(in particular, m.charAt(0)
) is left unchanged. d
的来源(尤其是m.charAt(0)
)保持不变。
You'll have to return the modified string manually: 您必须手动返回修改后的字符串:
function dxc(m) {
return stg(m.charAt(0)) + m.substring(1);
}
function stg(d) {
if (d === "d") {
return "p";
}else{
return d;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.