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 ...
 programming  I really need help in this it makes me confuse.I should make a ...
 computer science  9.10: Reverse Array Write a function that accepts an int ...
 Javascript  I would like the function test to get the input from the user and ...
 assembler language  write an assembly language subordinate count according to ...
 SQL  1 A SQL statement is needed to create a stored procedure that has one ...
 computer science  Im trying to create an arraylist that's sorted but I have no ...
More Related Questions