-1
我试图拧一个脚本,输出一个数组并根据用户输入计算数组中元素的数量。JavaScript计数函数
<script>
// Function searches a given array and counts the number of times an element appears in the array.
function countOccurences(numArray, num) // function
{ //parameters
var count = 0;
if(array[i] == 2)
count++;
}
</script>
</head>
<body>
<script>
var num = [2, 6, 33, 1, 77, 2, 98]; <!-- array -->
document.write("<p>"+nums.toString()+"</p>"); <!-- fill the array-->
var count = parseFloat(prompt("Please enter number to search for", "")); <!--ask for the numer to search -->
// linear search
var p = countOccurences(nums, key) ;
document.write("<p>Value "+p+" was not found in array </p>"); //output the count
</script>
</body>
</html>
这不是Java(而且你总是忘记语言标记)。你也没有问过一个实际的问题或解释这个代码有什么问题 – UnholySheep
这是什么问题?附: '' - JavaScript的错误评论 – FieryCat