Question

Define a JavaScript function named activityScore with one parameter. Assume the function will be called with...

Define a JavaScript function named activityScore with one parameter. Assume the function will be called with an array of Numbers. Define the function so that it creates an Object. This object should have a key equal to "score", and its paired value should be set to the sum of the array’s entries. Return the JSON blob encoding the Object.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Activityscores.html:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <!-- title for web page -->

    <title>Activity Scores</title>

</head>

<body>

    <!-- script is used for javascript -->

    <script>

    //function activityScore with one parameter numbers

    //here numbers is an array

    //this function will sum all the array elements and

    //return the JSON object

    function activityScore(numbers){

        var total=0;//variable used to store total of all array elements

        //using for loop to add each variable from the array numbers

        for(var k=0;k<numbers.length;k++)

        {

            //adding element from the array numbers to the variable total

            total+=numbers[k];

        }

        //creating object with key score and value is total

        var object='{"score":'+total+'}';

        //returning object as JSON

        return JSON.parse(object);

    }

    //call function activityScore() and print the sum of array elements

    console.log("activityScore( [ 25, 30, 32 ]):"+activityScore([25,30,32]).score);

   

    </script>

</body>

</html>

=========================

Output :

Add a comment
Know the answer?
Add Answer to:
Define a JavaScript function named activityScore with one parameter. Assume the function will be called with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Define a JavaScript function named showScores which has one parameter which is a JSON blob (JSON...

    Define a JavaScript function named showScores which has one parameter which is a JSON blob (JSON encoding). The parameter encodes an object which maps strings to Numbers. This object will have the keys: "total" and "count". Your function should display the parameter's value associated with "total" in a div element whose id is "overall" . It must also display the parameter's value associated with "count" in a div element whose id is "num".

  • In JavaScript define a function named 'lowInventory' which will be called with a dictionary mapping strings...

    In JavaScript define a function named 'lowInventory' which will be called with a dictionary mapping strings to numbers and which returns the number of key-value pairs whose value is lee than or equal to 10. Example: lowInventory({'milk':14,'butter':5,'bread':37,'jam':8}) must return 2 lowInventory{{'oil':16,'filter':29,'grease':42,'hydraulic fluid':18}) must return 0

  • use javascript please Complete the function below using recursion. Assume the parameter is a positive integer....

    use javascript please Complete the function below using recursion. Assume the parameter is a positive integer. The function will return an array that contains all of the numbers from 1 up to the parameter in consecutive order. For example, if the parameter is the value 5 then the return value should be the array [1, 2, 3,4 function makeSequence(value) t\ please use recursion thank von

  • create a javascript function named bbqFood that takes in an object and returns an array. The...

    create a javascript function named bbqFood that takes in an object and returns an array. The input object will have strings naming party foods as the key and the numbers of people that each key will feed as its values. return an array containing all of the keys whose values are greater than 10, menaing it will feed more than 10 people. example bbqfood(['taco':15, 'hamburger':6,'pasta':42,'fruit':23}) must return ['taco','pasta','fruit']

  • Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating...

    Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating point numbers. The function will make an HTTPS GET request to the url "https://fury.cse.buffalo.edu/ps-api/a" with a query string containing the same key-value pairs from the input key-value store. The response from the server will be a JSON string representing an object in the format "{"answer": <Number>}" where <Number> is a floating point Number. Return the value at the key "answer" as a float Recall...

  • python:Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating...

    python:Write a function named "query_dict" that a key-value store as a parameter mapping strings to floating point numbers. The function will make an HTTPS GET request to the url "https://fury.cse.buffalo.edu/ps-api/a" with a query string containing the same key-value pairs from the input key-value store. The response from the server will be a JSON string representing an object in the format "{"answer": }" where is a floating point Number. Return the value at the key "answer" as a float Recall that...

  • In JavaScript the inner function can access the variables from the outer scope even after the...

    In JavaScript the inner function can access the variables from the outer scope even after the outer function has returned. This is because the variables are still bound in the inner function and not dependent on the outer function. This is called closure. True False 3 points    QUESTION 2 Which of the following statements is true about JSON? a. JSON stands for JavaScript Object Notation. b. JSON is a syntax for storing and exchanging data. c. JSON is text,...

  • create a javascript function named sumBeyond that takes in an array of numbers and returns the...

    create a javascript function named sumBeyond that takes in an array of numbers and returns the summation of the values in the array that are greater than (but not including) 42. If there are no values greater than 42, the function should return 0. example- sumBeyond([2,85,932,0,7,-5,0,32]) must return 1017

  • In Javascript Define 2 functions in JSBin: - A function which receives an array of numbers...

    In Javascript Define 2 functions in JSBin: - A function which receives an array of numbers as an argument, and returns the product of all the numbers in that array.   For example, multiply([2,3,4]) should return 24. - A function which receives a string as an argument, and returns the reversal of that string.   For example, reverse('Hello there!') should return "!ereht olleH"

  • using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average...

    using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average that Receives two integer numbers as parameter and returns the average Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above Define a class named Student with following members: private data: 2 grades and a GPA (average). public constructor to initialize the members a public function...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT