Is it impossible to save the value of the variables without placing them outside? For the purpose of doing the function in an iterative way, do it recursively.
If there really is no way, why?
Save the value of the variables that are inside the function in order to do the function recursively, instead of using loops.
The purpose of the function is to show the table of a number, in this way the first parameter is the number of which you want to know the table , and the second the table size , so if the parameters are (4,10)
would be the table from 4 to 10 bone, (4*1 ... 4*10)
function ab(n,max){
var maximo=parseInt(max,10) || 0, // el maximo
contador = 1, // un contador
numeroParaMultiplicar = parseInt(n,10) || 0, // el numero para la tabla
numerosMultiplicados = []; // aqui se añadirá la tabla
if(contador <= maximo) { // mientras el contador sea igual o menor que el maximo especifcado se realizara el bucle
//numerosMultiplicados.push(numeroParaMultiplicar*contador);
numerosMultiplicados.push(numeroParaMultiplicar*contador); //multiplico
contador++; // se suma 1 al contador
ab(numeroParaMultiplicar,maximo); //vuelvo a llamar a la funcion
}
return numerosMultiplicados;
}
console.log(ab(4,10));