JavaScript

posted by .

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 -

    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.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. programming

    I really need help in this it makes me confuse.I should make a program to find a pattern...so can somebody help me... Write a function to recognize an pattern within another array. Your function should have the following prototype. …
  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. …
  3. SQL

    1- A SQL statement is needed to create a stored procedure that has one input parameter of data type int. The stored proc selects the supplierId field and the total, or sum, of all Count field values for each group of supplierId fields …
  4. JavaScript

    I need help these javascript exericses: Input: A text string, using prompt. Output: Either "Valid name" or "Invalid name", depending on whether the input names fit the required format, which is Last name,first name, middle initial …
  5. Javascript

    I need help these javascript exericses: Input: A text string, using prompt. Output: Either "Valid name" or "Invalid name", depending on whether the input names fit the required format, which is Last name,first name, middle initial …
  6. 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 …
  7. Javascript

    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++) …
  8. computer science

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should …
  9. assembler language

    write an assembly language subordinate count according to these specs: accepts a pointer to an array or signed words in register X. Accepts a word value in register Y, which indicates the number of array elementsl Returns the number …
  10. computer science

    Im trying to create an arraylist that's sorted but I have no idea how to sort the numbers. I cant use the array.sort method here is my code: public class Testing { private int [] data; private int count; private static int defCapacity …

More Similar Questions