//1-9任意插入加减号,值为100 //如:1+23-4+56+7+8+9=100 while(true){ let sum = "1" + ["","+","-"][Math.round(Math.random()*2)]; sum += "2" + ["","+","-"][Math.round(Math.random()*2)]; sum += "3" + ["","+","-"][Math.round(Math.random()*2)]; sum += "4" + ["","+","-"][Math.round(Math.random()*2)]; sum += "5" + ["","+","-"][Math.round(Math.random()*2)]; sum += "6" + ["","+","-"][Math.round(Math.random()*2)]; sum += "7" + ["","+","-"][Math.round(Math.random()*2)]; sum += "8" + ["","+","-"][Math.round(Math.random()*2)] + "9"; if(eval(sum) == 100){ console.log(sum + " = 100"); break; } }
目前代码只能随机生成一个,之后还会更新。