Question: This is the question Task 1: Play with numbers [10 marks] Using function declaration, define a JavaScript function (name it: playNumbers), which takes indefinite number

This is the question

Task 1: Play with numbers [10 marks]

Using function declaration, define a JavaScript function (name it: playNumbers), which takes indefinite number of parameters. This function does not return any value. Instead, (1) if the function call didn't pass any arguments, your function displays:

There are no inputs.

program terminates.

(2) if one or more arguments are not numbers, your function displays: (The parameter) is not a number. for all the arguments that are not a number. e.g. if the parameters are ("abc", 3, "hello"), your program displays: abc is not a number.

hello is not a number.

program terminates.

(3) Otherwise (if not (1) nor (2)), (3.1) it displays the largest value of all the parameters in the format:

The largest number of (para1, para2,...) is (the largest value). e.g., The largest number of (9, 3, 6) is 9. NOTE: You need to write the logic to get the largest value. Do not use the built-in function.

(3.2) it displays the average of all the values in the format: The average of (para1, para2, ...) is (the average). e.g., The average of (9, 3, 6) is 6.

1

(4) Test your program using the following statements.

console.log("/***************************** Task1 *************************/");

playNumbers(); playNumbers("abc", 3, "hello"); playNumbers(9,3,6); playNumbers(3,5,1,3,5); playNumbers("Good day!",3,4,32,"hi", "we");

output is as follows:

/***************************** Task1 *************************/ There are no inputs. abc is not a number. hello is not a number.

The largest number of (9, 3, 6) is 9 The average of (9, 3, 6) is 6 The largest number of (3, 5, 1, 3, 5) is 5 The average of (3, 5, 1, 3, 5) is 3.4 Good day! is not a number. hi is not a number. we is not a number.

This is my work can you please solve this within my work I am getting different output

function playNumbers()

{

var count = arguments.length;

var total = 0;

for(i=0;i

{

total += count;

}

if(count == 0)

{

console.log("There are no inputs");

}

console.log(total);

var i;

for(i=0;i

{

if (!Number(arguments[i]))

{

console.log(arguments[i] + " is not a number");

}

}

var largest = 0;

var count = arguments.length;

var i;

for(i=0;i

{

if (arguments[i]>largest)

{

largest = arguments[i];

}

}

console.log(largest);

var count = arguments.length;

var total=0;

var i=0;

var avg=0;

for(i=0;i

{

total+=arguments[i];

}

avg=total/count;

// return avg;

console.log(avg);

}

playNumbers();

playNumbers("abc", 3, "hello");

playNumbers(9,3,6);

playNumbers(3,5,1,3,5);

playNumbers("Good day!",3,4,32,"hi", "we");


 This is the question Task 1: Play with numbers [10 marks]

aljs-javaScript - Visual Studio Code JS fx2JS us fais dbs211.sal 35 all V OUTPUT [Done] exited with code-1 in 1.185 seconds [Running] node "c:\Users iyan OneDrive \Desktop\javasc There are no inputs NaN 9 abc is not a number hello is not a number 3 NaN 9 9 6 25 5 3.4 36 Good day! is not a number hi is not a number we is not a number 32 NaN (Done] exited with code in 1.212 seconds In e

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!