javascript岩石剪纸程序,停止在用户或pc达到的所需数量的点?

javascript岩石剪纸程序,停止在用户或pc达到的所需数量的点?,javascript,Javascript,这是我关于stackoverflow的第一个问题,我刚刚进入编程世界,我正在尝试编写一个javascript程序,该程序在用户或计算机达到的所需点数处停止。我目前正在codacademy学习它。我只需构建游戏,以显示谁在一次尝试中获胜。但我无法确定当用户或计算机达到所需数量的点时,为什么它不工作`在此处输入代码,请忽略缩进 var userPoints=0; var systemPoints=0; var points=prompt("Enter the no of po

这是我关于stackoverflow的第一个问题,我刚刚进入编程世界,我正在尝试编写一个javascript程序,该程序在用户或计算机达到的所需点数处停止。我目前正在codacademy学习它。我只需构建游戏,以显示谁在一次尝试中获胜。但我无法确定当用户或计算机达到所需数量的点时,为什么它不工作`在此处输入代码,请忽略缩进

    var userPoints=0;
    var systemPoints=0;
    var points=prompt("Enter the no of points for the game to be played");
    while(points>=userPoints || points>=systemPoints){
var user=prompt("enter rock or paper or scissor").toUpperCase();
var system=Math.random();
if(system>0&& system<0.34){
    system="ROCK";
}
else if(system>=0.37&& system<0.67){
    system="PAPER"
}
else{
    system="SCISSOR"
}
console.log("the user choice is"+" "+user);
console.log("the system choice is"+" "+system);
var compare=function(choice1,choice2){
    if(choice1===choice2){
        console.log("it's a tie");
    }
    else if(choice1==="ROCK"){
        if(choice2==="SCISSOR"){
            return "user wins";
            userPoints=userPoints+1;
        }
        else{
            return "system wins";
            systemPoints=systemPoints+1;
        }
    }
    else if(choice1==="PAPER"){
        if(choice2==="Rock"){
            return "user wins";
            userPoints=userPoints+1;
        }
        else{
            return "system wins";
            systemPoints=systemPoints+1;
        }
    }
    else if(choice1==="SCISSOR"){
        if(choice2==="PAPER"){
            return "user wins";
            userPoints=userPoints+1;
        }
        else{
            return "system wins";
            systemPoints=systemPoints+1;
        }
    }
    console.log("user points are"+userPoints);
console.log("system points are"+systemPoints);
};compare(user,system);
var userPoints=0;
var systemPoints=0;
var points=提示(“输入要玩游戏的点数”);
而(点>=用户点| |点>=系统点){
var user=prompt(“输入岩石、纸张或剪刀”).toUpperCase();
var system=Math.random();
如果(system>0&&system=0.37&&system我认为这一行:

(points >= userPoints || points >= systemPoints)
您可能希望使用“&&”而不是“| |”。从目前的情况来看,只要用户或系统低于最大点数,它就会继续。您希望只有当两者都低于最大点数时,它才会继续(因为一旦其中一项结束,游戏就应该结束)

其次,当你进行比较时:

if(choice2==="SCISSOR"){
    return "user wins";
    userPoints=userPoints+1;
}
您在更新userPoints之前返回,因此userPoints永远不会更改。您应该反转这些行(在每次进行比较时)


如果您使用的是Chrome或IE等浏览器(可能还有其他浏览器),则可以在开发人员控制台(F12)中调试代码通过设置断点并逐步通过它…这将允许您快速发现第二个问题。

一般来说,您应该尝试将发布的代码减少到演示问题所需的最小数量-发布一个大块,然后询问出现了什么问题,很少能得到好的答案。谢谢@nrabinowitz,因为我已经我是这里的新手,谢谢你的建议。下次我会记住这一点,恐怕我不能这样做,因为我不知道实际错误在哪里!!根据我的经验,努力找到重现错误所需的最低代码通常可以让你自己调试错误:)。如果您不愿意这样做,用户可能也不会。谢谢@Beska u说得对,但尽管这样做了,代码还是不起作用。@PrudhviReddy添加了第二个问题。