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
alukav5142 [94]
3 years ago
12

Add a throw statement to the processNumbers function that throws the message "All elements in the list should be numbers." if on

e of the elements in numberList is not a number. Hint: The function isNaN() returns true if the parameter is not a number.
Computers and Technology
1 answer:
Tju [1.3M]3 years ago
5 0

Answer:

  1. function processNumbers(numList){
  2.    try{    
  3.        for(let i=0; i < numList.length; i++){
  4.            if(isNaN(numList[i])){
  5.                throw "All elements in the list should be numbers.";
  6.            }
  7.            
  8.        }
  9.    }
  10.    catch(err){
  11.        console.log(err);
  12.    }
  13. }
  14. let myList = [4, 6, 1, "abc", 9];
  15. processNumbers(myList);

Explanation:

The solution code is written in JavaScript as the isNaN() is an in-built function in JavaScript.

Firstly, create a function processNumbers that takes one input number list, numList (Line 1).

To handle the possible Not a Number (NaN) error, create a try and catch block. In the try block, create a for-loop to traverse through the numList array and use isNaN function to check if the current value is a number (Line 3 - 4). If it is not a number, isNaN will return true and the program will run the throw statement (Line 5). The throw message will be passed to the catch block and display it on console (Line 10 - 12).

We can test the function by using the sample list (Line 15 - 16) and we shall see the thrown error message is displayed.  

You might be interested in
A _______ acts as a security buffer between a corporation's private network and all external networks.
Contact [7]
The answer is a firewall. It is a system that will block potentially harmful software or websites from accessing your computer.
3 0
3 years ago
"ikev2 requires the use of which of authentication protocol?"
katen-ka-za [31]
Ikev2 requires the use of authentication protocol called Extensible Authentication Protocol (EAP).  It is <span>is a protocol for wireless networks that ampiflies on the authentication methods for the Point-to-Point Protocol (PPP).</span>
4 0
3 years ago
The command prompt is currently in the Old_Data folder. Which two commands can you use to create a new folder called Archive?
Ksivusya [100]

Answer:

mkdir Archive

Explanation:

Assuming that you want to create the new folder within the Old_Data folder then you would only need one command which is the mkdir command. This will create the folder inside the current location which in this case is the Old_Data folder. Like so...

mkdir Archive

Otherwise, you would first need to navigate to the folder that you want to create the new folder. You do this using the "cd /" to navigate to previouse directory and then to the one you want.

7 0
3 years ago
What trends do you see in the industry in 2010? For example, if there were more or fewer jobs created by travel and tourism, rep
Setler [38]

Answer:

i saw phones and more social media being used mobile gaming was also invented

Explanation:

me smart birb

4 0
4 years ago
Read 2 more answers
What is control structure write it's types​ .
MAXImum [283]

Answer

<u>Defination</u><u>-</u><u>:</u>

A control statement is a statement and a statement whose execution its control.

<u>Types-:</u>

  • Selection Statement
  • Iteration Statement
  • Unconditional branching Statement
4 0
3 years ago
Other questions:
  • In dt.py, you will implement a basic decision tree classifier for
    5·1 answer
  • You want to transfer a document from one computer to another, and you want the document to be encrypted. The destination compute
    14·1 answer
  • Which of the following does not illustrate the survey method of choosing a speech topic?
    6·2 answers
  • John works as an associate at a construction company. His job is to draft contracts for suppliers. Before he prints the contract
    7·1 answer
  • What would be the best thing you could do to prepare yourself to work for a company that has embraced globalization. A) learn ho
    12·2 answers
  • Write a program that simulates rolling one die using the following steps: 1. Prompt the user for the number of sides on the die.
    13·1 answer
  • Reflect on the questions below.
    7·1 answer
  • A printer is considered to be in the category of
    5·2 answers
  • An attacker obtains a connection to your LAN and then uses SETH to perform a MiTM attack between your system and the company RDP
    10·1 answer
  • Gnome ____ are small programs available on the gnome panel that are designed to give you quick access to useful applications.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!