我试图用不同的输入重复一个函数 5 次。问题是,该函数在 for 循环之外可以正常工作,但在它内部它只能工作 1 次。这是我的代码:
var string;
var num;
function comandos(string, num){
let resultado = "";
for (i=0; i<string.length; i++){
if (string.charAt(i) == "i"){
num = num + 1;
}else if (string.charAt(i) == "d"){
num = num - 1;
}else if (string.charAt(i) == "c"){
num = Math.pow(num, 2);
}else if (string.charAt(i) == "p"){
resultado = resultado + "*" + num + "*";
}
}
return resultado;
}
for (i=0; i<5; i++){
string = prompt("Ingrese secuencia de comandos (i, …Run Code Online (Sandbox Code Playgroud)