Posted by **Adam Johnson** on Tuesday, November 15, 2011 at 2:50am.

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, zeros, and values greater than zeros in the given array. I don't understand how the switch statement are suppose to implement it.

- JavaScript -
**Dr Russ**, Tuesday, November 15, 2011 at 3:37am
You are probably best to post the method so far. However, switch statements are shorthands for a group of if statements that all relate to the same quantity as:

if (x == 0) doSomething0();

else if (x == 1) doSomething1();

else if (x == 2) doSomething2();

else if (x == 3) doSomething3();

else if (x == 4) doSomething4();

else doSomethingElse();

So in your case you need to read the value from the array called numbers,

{

for (int counter=0, counter<numbers.length, n++)

{

x=numbers[counter];

// now use the if statements to count how many of each type there are in the array. For clarity you will need to declare three variables for number of negatives, positives and zeros. For example

int negatives=0;

int positives=0;

int zeros=0;

then use the switch statements to count each of the tree types.

## Answer This Question

## Related Questions

- Javascript - I need help these javascript exericses: Input: A text string, using...
- JavaScript - I need help these javascript exericses: Input: A text string, using...
- Javascript - How do take this following javascript and put in external ...
- programming - JavaScript - /*Hello, I really hope someone can help me out with ...
- computer science - Create a method called countZeros, which takes an integer ...
- Javascript - I would like the function test to get the input from the user and ...
- Calculus - For any constant c, define the function f_c(x)= x^3+2x^2+cx. (a) ...
- Calculus - For any constant c, define the function f_c(x)= x^3+2x^2+cx. (a) ...
- computer science - 9.10: Reverse Array Write a function that accepts an int ...
- SQL - 1- A SQL statement is needed to create a stored procedure that has one ...

More Related Questions