Question

Create a JavaScript function named display_data that has two parameters. The first parameter will be a...

Create a

JavaScript

function named

display_data

that has two parameters. The first

parameter will be a

String

containing a JSON blob like the function in part 1 returns. The

second parameter will be a boolean.

Start by using the JSON library to convert the first parameter into a usable JavaScript Object.

Next get the HTML element whose

id

is

"data". This HTML element is a

div.

If the second parameter is equal to

true

​, write the value associated with the Object's

"total"

key into the

div

. If the second parameter is equal to

false

, write the value associated with the

Object's

"average"

key into the

div

Examples are also not possible for this problem. Sorry, again!

After completing this part of the lab exam you should download the repl as a ZIP file and submit

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

Javascripts:

function display_data(id, type) {

document.getElementById(id).innerText = type ? "total" : "average";

}

Sample program to test:

key.js

function display_data(id, type) {

document.getElementById(id).innerText = type ? "total" : "average";

}

window.onload = () => {

display_data("divTag", true)

}

HTML:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

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

<title>Array</title>

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

<script src="key.js"></script>

</head>

<body>

<div id="divTag"></div>

</body>

</html>

Output:

Add a comment
Know the answer?
Add Answer to:
Create a JavaScript function named display_data that has two parameters. The first parameter will be a...
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".

  • 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.

  • javascript-Write a function named "json_average" that takes a JSON formatted string as a parameter in the...

    javascript-Write a function named "json_average" that takes a JSON formatted string as a parameter in the format of an array of objects where each object has keys "mass", "density", "temperature", and "velocity" and each key maps to a floating point number. This function should return the average "velocity" of all the objects in the array as a JSON string in the format {"velocity": }

  • help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and...

    help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...

  • Create a function named first_is_smaller(...) which receives two integer parameters (n1 and n2) and returns a...

    Create a function named first_is_smaller(...) which receives two integer parameters (n1 and n2) and returns a Boolean value True if the value in the first parameter is smaller than the second and False otherwise. As an example, the following code fragment: print(first_is_smaller(10,20)) should produce the output: True Language: Python

  • Functionality to build (4 functions) read_csv_header Define a function named read_csv_header with one parameter. This parameter...

    Functionality to build (4 functions) read_csv_header Define a function named read_csv_header with one parameter. This parameter will be a csv reader object (e.g., the value returned when calling the function csv.reader). The first row read using the parameter is the file's header row. The header row contains the keys for the data stored in the CSV file. This function must return a list containing the strings from that header row. The function parameter will be a csv reader object and...

  • Need in Python! Write a function definition named  power  that takes two formal parameters which can be assumed...

    Need in Python! Write a function definition named  power  that takes two formal parameters which can be assumed to be any numeric type. The first parameter is called base, the second is called exponent. The function should return the result of the base raised to the exponent power.    You may not use any Python math library functions inside your function. You may create your own code to test the function in an IDE if you wish.   HINT: The exponent operator in...

  • Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for...

    Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the...

  • Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters:...

    Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters: an unsigned doubleword array and the length of the array. The function must return the value of the largest array member in eax. Preserve all registers (except eax) that are modified by the function. Write a test program in main that calls findLargest three times, each call using a different array with different lengths. Function called countHits Write a function called named countHits that...

  • Define a function called DisplayMax that has 3 parameters: the first two parameters are parallel arrays...

    Define a function called DisplayMax that has 3 parameters: the first two parameters are parallel arrays of different types and the third argument is of type size_t representing the size of both arrays. The function DisplayMax must work when called with various types of actual arguments, for example string DisplayMax(string names[], int calories[], int size) or int DisplayMax(int calories[], float prices[], int size). (Parallel Arrays are two arrays whose data is related by a common index. For example: with the...

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