Monday
April 21, 2014

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 - 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...
A good programming forum??? - I'm working with VBScript and Javascript all the ...
Computer Science-Javascript - Can you check my code and tell me why the prompts ...
Javascript - Can you check my code and tell me why the prompts are not showing ...
computers-html/javascript - when working in notepad, i need to use pop-up boxes...
Physics - What is the decimal equivalent of 3.14 10^7? is this the decimal ...
Javascript - Input: A text string, using prompt. Output: Either "Valid name" or...
computers-html/javascript - when working in notepad, i need to use pop-up boxes...

Search
Members