简体   繁体   English

您如何制作整个OWN语言编码器? 我试过了..(不起作用)

[英]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 您忘了returnreturn的值

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.

相关问题 如果鼠标不移动,如何使覆盖淡出? - How do you make an overlay fade out if your mouse doesn't move? 我将整个JS文件放在无法单独使用的新函数中后无法正常工作 - Entire JS file not working after I place in a new function that doesn't work on it's own 我试图在浏览器中制作一个画家,但后来它制作了一个“橡皮擦”,但它不起作用,因为它不会改变颜色 - I tried to make a painter in browser, but then it went to making an 'eraser' it didn't work because it doesn't change the color 我尝试使用引导程序模式类制作弹出式注册表单,但弹出式窗口不起作用 - I tried to use bootstrap modal class to make a popup signup form but popup doesn't work 我试图在没有教程的情况下在 JS 中制作 Color Flipper,但它不起作用 - I tried to make a Color Flipper in JS without tutorials and it doesn't work 如何使元素在整个 href 卡中不能用作 href - how do I make an element not work as href in an entire href card 如何在Jest中手动模拟自己的一个文件? - How do you manually mock one of your own files in Jest? 我如何做到这一点,如果你按下一个按钮,然后再按下一个不同的按钮,你会在屏幕上看到一些东西? - How do i make it so that if you press a button and then a different button you will get something written on your screen? 我试图使每个按钮增加他自己的div中输入的数字,但是不起作用 - I'm trying to make each button increase the numbers in the input in his own div but doesn't work 我试图用 fetch 更新我的 ejs 页面,但它不起作用 - i tried to upate my ejs page with fetch but it doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM