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
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
lyudmila [28]

I am not able to open the pdf kindly send the jpg form.

4 0
3 years ago
Read 2 more answers
Assume that an array of integers named a that contains exactly five elements has been declared and initialized. Write a single s
Alik [6]

array[0] = 2 * array[4];

5 0
3 years ago
Peripherals are part of the main computer.<br><br> True<br> False
LenKa [72]

Answer:

False

Explanation:

Peripherals are devices outside the main computer. They add to the functions of the main computer but the main computer can still power on without them. So this is how you can distinguish what is part of the main computer.

Peripherals can come as input or output devices. Input devices are devices like the keyboard, mouse, and the like. Output devices are things like scanners, printers, monitors, speakers and the like.

3 0
3 years ago
Read 2 more answers
What kind of company would hire an Information Support and Service employee?
Anni [7]
A service company would hire an Information Support and Service employee.

hope it helps you!
6 0
4 years ago
Read 2 more answers
You are trying to connect a new USB device to your computer. You install the driver and then connect the device to an open USB
nadezda [96]

Answer:

By order of increasing magnitude:

D. Make sure the USB device is plugged in properly.

A. Try a different USB cable.

B. Replace the USB device.

C. Install a new USB controller card.

Explanation:

Start with whatever is simplest first. Most errors are simply ID-10-T mistakes.

3 0
3 years ago
Other questions:
  • This question involves the creation of user names for an online system. A user name is created based on a user’s first and last
    13·1 answer
  • Walking paths across the part is represented by the equation why equals -4x - 6​
    9·1 answer
  • The background image does not affect any cell’s format or content. _______
    5·1 answer
  • Explain The Two Way Communication in full.
    10·1 answer
  • Atms typically use single factor authentication. <br> a. True <br> b. False flashcard
    5·1 answer
  • Write calls to printf to display the variable x in the following formats:
    8·1 answer
  • How many bits per pixel does a black and white image require?
    15·1 answer
  • Write a program that reads integers from the user and stores them in a list. Your
    15·1 answer
  • Information about www
    14·1 answer
  • What were the names of Henry VIII's six wives?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!