js输入n得到n的数组问题

JavaScript023

js输入n得到n的数组问题,第1张

function arr()

{

var tmpArr = new Array()

var n = prompt("Please enter a number","0")

if (isNaN(n) || n<=0)

{

return 0

}

else if (n>0)

{

for (i = 0i <ni++)

{

tmpArr[i] = i

}

return tmpArr

}

}

document.write(arr())

while(true){

    var obj = prompt("输入一个整数:","")

    if(/^\+?\d+$/.test(obj)){

        var sum = 0

        for(var i = 1 i <= obj i++){

            var x = 1

            for(var j = 1 j <= i j++){

                x *= j

            }

            sum += x

        }

        alert("1的阶乘到"+obj+"的阶乘的和: " + sum)

        break

    }else{

        continue

    }

}