Thursday
May 23, 2013

Homework Help: Javascript

Posted by Adam on Monday, November 21, 2011 at 6:31pm.

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>

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Javascript - Can you check my code and tell me why the prompts are not showing ...
Computer Science-Javascript - Can you check my code and tell me why the prompts ...
JavaScript - I'm working on a javascript exercise. I have written function ...
Javascript - I need help these javascript exericses: Input: A text string, using...
JavaScript - I need help these javascript exericses: Input: A text string, using...
Javascript - I would like the function test to get the input from the user and ...
computers-html/javascript - when working in notepad, i need to use pop-up boxes...
computer programming (PYTHON) - My first page is &lt;html&gt; &lt;...
computer programming (PYTHON) - My first page is &lt;html&gt; &lt;...
JAVASCRIPT - Start button won't work for a scolling marquee. Below is the ...

For Further Reading

Search
Members
Community