Javascript函数赢得';“不接受输入”;未捕获的引用错误:未定义p“;

Javascript函数赢得';“不接受输入”;未捕获的引用错误:未定义p“;,javascript,math,Javascript,Math,在Chrome中测试时会出现问题,但我相信它会在任何浏览器中出现 为什么会出现错误:“uncaughtreferenceerror:p未定义”?我只是想传递一些数字和指令,例如doControllerConversion(p,tr,300);但它却错了。是因为我没有使用字符串吗?我在这里束手无策 非常感谢。我是个彻头彻尾的笨蛋 function doControllerConversion(s1, o1, u1) { var selector; var orientation;

在Chrome中测试时会出现问题,但我相信它会在任何浏览器中出现

为什么会出现错误:“uncaughtreferenceerror:p未定义”?我只是想传递一些数字和指令,例如doControllerConversion(p,tr,300);但它却错了。是因为我没有使用字符串吗?我在这里束手无策

非常感谢。我是个彻头彻尾的笨蛋

function doControllerConversion(s1, o1, u1) {

    var selector;
    var orientation;
    var userInput;
    s1 = selector;
    o1 = orientation;
    u1 = userInput;

    if (UserSettings.controllerType == "KH606") {
        if (selector == 'p') {
            if (orientation == "toRtraw") {
                return userInput * 2.85;
            } else if (orientation == 'fr') {
                return userInput / 2.85;
            }
        } else if (selector == 'b') {
            if (orientation == "tr") {
                return userInput * 5.10;
            } else if (orientation == 'fr') {
                return userInput / 5.10;
            }
        } else {
            return errorOut(1);
        }
    }

    if (UserSettings.controllerType == "KH609") {
        if (selector == 'p') {
            if (orientation == 'tr') {
                return userInput * 2.46;
            } else if (orientation == 'fr') {
                return userInput / 2.46;
            }
        } else if (selector == 'b') {
            if (orientation == 'tr') {
                return userInput * 5.10;
            } else if (orientation == 'fr') {
                return userInput / 5.10;
            }
        } else {
            return errorOut(1);
        }
    }

    if (UserSettings.controllerType == "KH612") {
        if (selector == 'p') {
            if (orientation == 'tr') {
                return userInput * 1.20;
            } else if (orientation == 'fr') {
                return userInput / 1.20;
            }
        } else if (selector == 'b') {
            if (orientation == 'tr') {
                return userInput * 2.73;
            } else if (orientation == 'fr') {
                return userInput / 2.73;
            }
        }
    }

    if (UserSettings.controllerType == "KH615") {
        if (selector == 'p') {
            if (orientation == 'tr') {
                return userInput * 0.79;
            } else if (orientation == 'fr') {
                return userInput / 0.79;
            }
        } else if (selector == 'b') {
            if (orientation == 'tr') {
                return userInput * 2.55;
            } else if (orientation == 'fr') {
                return userInput / 2.55;
            }
        }
    }

    if (UserSettings.controllerType == "KH618") {
        if (selector == 'p') {
            if (orientation == 'tr') {
                return userInput * 0.53;
            } else if (orientation == 'fr') {
                return userInput / 0.53;
            }
        } else if (selector == 'b') {
            if (orientation == 'tr') {
                return userInput * 1.70;
            } else if (orientation == 'fr') {
                return userInput / 1.70;
            }
        }
    } else {
        console.log("Error on basic conversion!");
    }

}

在严格模式下,您必须定义所有变量、函数等。

问题在于您发送的参数,请检查您是否将字符串值传递给函数, 将其发送为:

doControllerConversion('p','tr',300) 

似乎正在工作

是否确定已定义要传递到函数中的p变量?文件控制器转换(p,tr,300);看起来您还没有在调用函数的范围内定义p。这行代码也可以使用:s1=选择器;我想我会的,我想这就是答案!我觉得自己像个笨蛋!非常感谢。