Tuesday
March 31, 2015

Homework Help: Javascript

Posted by Adam on Tuesday, November 22, 2011 at 11:53pm.

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');
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Javascript - How do take this following javascript and put in external ...
JAVASCRIPT - Start button won't work for a scolling marquee. Below is the ...
Computer Science - I have defined a microscopic verson of scheme that utilizes ...
Statistics - Joint probability density function is: x + y where 0<x<1 and ...
programming - JavaScript - /*Hello, I really hope someone can help me out with ...
Computer Science - Suppose X is a random variable and Y = aX + b is a linear ...
algebra - The test scores from Mrs. Gray's Math class are shown below. 72, 73, ...
Programming - Design a program in pseudocode that calculates the amount of money...
Programming - Design a program in pseudocode that calculates the amount of money...
Javascript - I need help these javascript exericses: Input: A text string, using...

Members