Javascript

posted by .

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>

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. Computer Science-Javascript

    Can you check my code and tell me why the prompts are not showing up on the webpage: <html> <Head> <title>Homework 8</title> </Head> <body> I like the color purple.<br> </br> <scriptlanguage="javascript" …
  2. Javascript

    Can you check my code and tell me why the prompts are not showing up on the webpage: <html> <Head> <title>Homework 8</title> </Head> <body> I like the color purple.<br> </br> <script …
  3. programming - JavaScript

    /*Hello, I really hope someone can help me out with this function. I'm a newbie to JavaScript. I have included the instructions for the swapFE() function that I have to complete below along with the functions that I have done so far. …
  4. JAVASCRIPT

    Start button won't work for a scolling marquee. Below is the javascript code. window.onload = defineMarquee; var timeID; var marqueeTxt = new Array; var marqueeOff = true; function defineMarquee() { var topValue = 0; var allElems = …
  5. JavaScript

    I need help these javascript exericses: Input: A text string, using prompt. Output: Either "Valid name" or "Invalid name", depending on whether the input names fit the required format, which is Last name,first name, middle initial …
  6. Javascript

    I need help these javascript exericses: Input: A text string, using prompt. Output: Either "Valid name" or "Invalid name", depending on whether the input names fit the required format, which is Last name,first name, middle initial …
  7. JavaScript

    I'm working on a javascript exercise. I have written function called count where the count function take in one parameter and the parameter is a array of number. The problem I having is how do i return the numbers of negative elements, …
  8. Javascript

    I would like the function test to get the input from the user and display the like the counter function and to display if it passed or not. var negatives =0; var zeroes =0; var positives=0 ; function counter(array){ var i=0; for(i=0;i<array.length;i++) …
  9. Computer science

    I want to make my traffic lights run automatically without any user input. I have created this code so far but the images don't show up please help. My code: <!DOCTYPE html> <html> <head> <script type="text/javascript"> …
  10. Stat & Prob.

    Show that if Cov(X,Y)=0, then the correlation coefficient satisfies p(X+Y, X-Y)=Var(X)-Var(Y)/ Var(X)+Var (Y)

More Similar Questions