Javascript
posted by Adam .
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++)
{
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 show_prompt(){
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);
}
function test() {
var myIntArray = new Array(3);
myIntArray [0]=1;
myIntArray [1]=0;
myIntArray [2]=1;
counter(myIntArray);
if(zeroes ==1 && positives ==1 && negatives ==1) {
alert('Test passed');
}
else alert('Test Failed');
}

You might like some of the following Javascript Tutorials:
http://www.google.com/search?q=Javascript+tutorials&ie=utf8&oe=utf8&aq=t&rls=org.mozilla:enUS:official&client=firefoxa
Sra
Respond to this Question
Similar Questions

Computer Science
I have defined a microscopic verson of scheme that utilizes amb. I am currently using Dr. Scheme. This is my definition: (define (ambeval s environment succeed fail) (cond ((not (pair? 
Statistics
Joint probability density function is: x + y where 0<x<1 and 0<y<1 (0 elsewhere) Find variance of (30x + 25y) Answer is 11.48  My calculations Marginal probability density functions (same for x and y): f(x) = x + 1/2 … 
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. … 
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 = … 
financial statistics
Can you construct a pair of random variables such that Var(X)=Var(Y)=1 and Cov(X,Y)=2? 
statistics
The profit for a new product is given by Z = 2X  2Y  7. We know that X and Y are independent random variables with Var(X) = 2 and Var(Y) = 2.7. What is the variance of Z? 
Javascript
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 … 
Computer Science
Suppose X is a random variable and Y = aX + b is a linear function of X. Show that the correlation of X and Y is 1 if a < 0. cor(X,Y) = cov(X,V)/ sqrt(var(X)*var(Y)) 
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"> … 
Stat & Prob.
Show that if Cov(X,Y)=0, then the correlation coefficient satisfies p(X+Y, XY)=Var(X)Var(Y)/ Var(X)+Var (Y)