posted by .

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;
switch (true )
case (array[i] == 0) :
case (array[i] > 0) :
positives ++;
case (array[i] < 0) :
negatives ++;

return "Negatives = "+negatives+"\nZeroes = "+zeroes+"\nPositives = "+positives;
function show_prompt(){

var myIntArray = new Array(10);
var i=0;
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;
if(zeroes ==1 && positives ==1 && negatives ==1) {
alert('Test passed');
else alert('Test Failed');

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. Computer Science

    I have defined a microscopic verson of scheme that utilizes amb. I am currently using Dr. Scheme. This is my definition: (define (amb-eval s environment succeed fail) (cond ((not (pair?
  2. 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 …
  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. …

    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. financial statistics

    Can you construct a pair of random variables such that Var(X)=Var(Y)=1 and Cov(X,Y)=2?
  6. 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?
  7. 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 …
  8. 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))
  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