Asked by Adam
How do take this following javascript and put in external javascript.
<html>
<head>
<script language="javascript" type="text/javascript">
test();
function counter(array){
var negatives =0;
var zeroes =0;
var positives=0 ;
var i=0;
for(i=0;i<array.length;i++)
{
switch (true )
{
case (array[i] == 0) :
zeroes++;
break;
case (array[i] > 0) :
positives ++;
break;
case (array[i] < 0) :
negatives ++;
break;
}
}
return "Negatives = "+negatives+"\nZeroes = "+zeroes+"\nPositives = "+positives;
}
function test(){
var myIntArray = new Array(10);
var i=0;
for(i=0;i<10;i++){
var num = prompt("Please enter a number","Please enter a number");
myIntArray[i] = parseInt(num);
}
var output = counter(myIntArray);
alert (output);
}
</script>
</head>
<body onload="test()">
</body>
</html>
<html>
<head>
<script language="javascript" type="text/javascript">
test();
function counter(array){
var negatives =0;
var zeroes =0;
var positives=0 ;
var i=0;
for(i=0;i<array.length;i++)
{
switch (true )
{
case (array[i] == 0) :
zeroes++;
break;
case (array[i] > 0) :
positives ++;
break;
case (array[i] < 0) :
negatives ++;
break;
}
}
return "Negatives = "+negatives+"\nZeroes = "+zeroes+"\nPositives = "+positives;
}
function test(){
var myIntArray = new Array(10);
var i=0;
for(i=0;i<10;i++){
var num = prompt("Please enter a number","Please enter a number");
myIntArray[i] = parseInt(num);
}
var output = counter(myIntArray);
alert (output);
}
</script>
</head>
<body onload="test()">
</body>
</html>
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.