1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mars1129 [50]
3 years ago
5

Write a function named countEvens that counts and returns the number of even integers in an array. The function must have this h

eader: function countEvens(list) For example, if the countEvens function were called like this: var list = [ 17, 8, 9, 5, 20 ]; var count = countEvens(list); The countEvens function would return 2 because 8 and 20 are even integers.

Computers and Technology
1 answer:
skelet666 [1.2K]3 years ago
4 0

Answer:

function countEvens(list) {

   // IMPLEMENT THIS FUNCTION!

var even = [];

 

for(var i = 0; i < list.length; i++){

 if (list[i] % 2 == 0){

   even.push(list[i]);

   

 }

}

 return console.log(even)

}

var list = [ 17, 8, 9, 5, 20 ];

var count = countEvens(list);

Explanation:

The programming language used is JavaScript.

An even variable is initialized, to hold  the even variables within list.

A FOR loop loop iterates through all the elements in the list, an IF statement is used to check using the modulo division to check if the elements in the list are even.

The even elements are appended to the even list using .push() method.

Finally, the function returns the even list and outputs the list to the log using console.log(even) .

A list is created and the function is called.

You might be interested in
What is indexing ? How does it make search engines work more efficiently?
timama [110]

Indexing. The purpose of storing an index is to optimize speed and performance in finding relevant documents for a search query. Without an index, the search engine would scan every document in the corpus, which would require considerable time and computing power.

4 0
4 years ago
Write a program that first gets a list of integers from input. Then, get another value from the input, and output all integers l
jonny [76]

Answer:

The c++ program for the given scenario is given below.

#include <iostream>

using namespace std;

int main() {

   int len=20, arr[len], data;    

   // initialize all elements of the array to 0

   for(int i=0; i<len; i++)

   {

       arr[i] = 0;

   }    

   cout<<"This program outputs all the numbers less than or equal to the given number."<<endl;

   cout<<"Enter the list of numbers. Enter 0 to stop entering the numbers. "<<endl;

   for(int i=0; i<len; i++)

   {

       cin>>arr[i];        

       // 0 indicates user wishes to stop entering values  

       if(arr[i] == 0)

           break;

       else

           continue;

   }    

   // number from which the list is to be compared

   cout<<"Enter the number to be compared."<<endl;

   cin>>data;

     

   cout<<"The values less than or equal to the number "<<data<<" are "<<endl;

   for(int i=0; i<len; i++)

   {  

       // 0 indicates the end of the list entered by the user

       if(arr[i]==0)

           break;

       if(arr[i] <= data)

           cout<<arr[i]<<endl;

   }    

   return 0;    

}  

OUTPUT

This program outputs all the numbers less than or equal to the given number.

Enter the list of numbers. Enter 0 to stop entering the numbers.  

23

45

67

89

10

0

Enter the number to be compared.

59

The values less than or equal to the number 59 are  

23

45

10

Explanation:

This program takes input only from the user and makes no assumptions.

The list of numbers entered by the user are stored in an array. If the user input is less than the size of the array, the remaining elements are set to 0.

While taking input from the user, if any element of the array is found to be 0, the loop is discontinued.

for(int i=0; i<len; i++)

   {

       cin>>arr[i];        

       if(arr[i] == 0)

           break;

       else

           continue;

   }  

Same test is applied when all the numbers less than the given number are displayed.

for(int i=0; i<len; i++)

   {  

        if(arr[i]==0)

           break;

       if(arr[i] <= data)

           cout<<arr[i]<<endl;

   }

The above program takes into account all the specifications in the given question.

5 0
3 years ago
Of the following choices, what indicates the primary purpose of an intrusion detection system (IDS)?
MrRa [10]
That would be (A) because an IDS stands for Intrusion detection system which means that when there’s malicious activity or policy violations. Any malicious activity or violation is typically reported either to an administrator.
8 0
3 years ago
This refers to the people involved in the data processing operation.
yawa3891 [41]
The people involved in the data processing operation are known as <span>Peopleware.</span>
6 0
3 years ago
Which of the following does not use a Graphic User Interface?
meriva

UNIX is operating system has no graphics user interface

Unix

<u>Explanation:</u>

Mostly nowadays all operating system and software is coming at graphics user interface. End user what all are visual interfaces by using mouse as input tools.

Since computer world is changes technology every day mouse and graphics user interfaces. In old days where operating system are operated in black and white screen period main use of input device are keyboard and those days are no graphic user interface.

In fact nowadays we going back to black and white screen and we name it as dark mode and say to save current and save eyes. But still use mouse as input tools in dark mode also.

3 0
3 years ago
Other questions:
  • A process-based DO/S must synchronize actions across the network. When a process reaches a point at which it needs service from
    6·1 answer
  • Skinner designed a soundproof apparatus, often equipped with a lever or bar, with which he conducted his experiments in operant
    9·1 answer
  • Which is the most used operating system? A. Windows B.Linux C.Leopard D. DOS
    14·2 answers
  • A(n) ____ is a logical grouping of several data files that store data with similar characteristics.
    8·1 answer
  • Describe each of the six steps of the selection process as illustrated in chapter 12
    13·1 answer
  • How does is make you feel when you're kind to others? What are some opportunities in your life to be more kind to your friends a
    9·1 answer
  • With his assembly lines, Henry Ford improved what process? A. computer management B. just-in-time management C. Bessemer process
    5·1 answer
  • Which UML relationships should be used between a subclass and a superclass? For example, suppose there is an interface or abstra
    5·1 answer
  • Wml script is used in? ​
    14·1 answer
  • How have the computers contributed in the banking ?<br>​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!