我正在尝试在其基本阶段制作一个 javascript 项目,其中脚本应提示用户,询问一个数字作为输入,将数字转换为字母并将其显示给用户。然而,它不能正常工作的脚本。
<html>
<head>
<script type="text/javascript">
function num()
{
var arr1=new Array();
var arr2=new Array();
var i;
var start=0;
var end=start + 1;
arr1[0]=prompt('Enter Number');
for (i=0;i<2;i++)
{
arr2[i]=arr1[0].slice(start, end);
arr2[i]=parseInt(arr2[i]);
start++;
end=start + 1;
switch(arr2[i])
{
case 1:
document.body.innerHTML = document.body.innerHTML + 'one';
break;
case 2:
document.body.innerHTML = document.body.innerHTML + 'two';
break;
case 3:
document.body.innerHTML = document.body.innerHTML + 'three';
break;
case 4:
document.body.innerHTML = document.body.innerHTML + 'four';
break;
case 5:
document.body.innerHTML = document.body.innerHTML + 'five';
break;
case 6:
document.body.innerHTML = document.body.innerHTML + 'six';
break;
case 7:
document.body.innerHTML = document.body.innerHTML + 'seven';
break;
case 8:
document.body.innerHTML = document.body.innerHTML + 'eight';
break;
case 9:
document.body.innerHTML = document.body.innerHTML + 'nine';
break;
}
}
}
onload=num();
</script>
</head>
<body>
</body>
</html>