Javascript createSelectOptions function The function createSelectOptions should exist. The function createSelectOptions returns undefined if no data parameter is provided. The function createSelectOptions returns an array. The function createSelectOptions returns an array with the correct length. The function createSelectOptions returns an array of option elements. The function createSelectOptions assigns the related user id to the value attribute of the options elements. The function createSelectOptions assigns the related user name to the textContent attribute of the options elements. createSelectOptions a. Test users JSON data available here: https://jsonplaceholder.typicode.com/users b. For testing (not in function) you may want to define users with the test data. c. Receives users JSON data as a parameter d. Returns undefined if no parameter received e. Loops through the users data f. Creates an option element for each user with document.createElement() g. Assigns the user.id to the option.value h. Assigns the user.name to the option.textContent i. Return an array of options elements  Here is what I have written but it is failing everything.  The only thing that passed was that I created a function with the correct name. function createSelectOptions(users) {   array = [];   function getUser(item) {     array.push(item.id);   }   data.forEach(getUser);   return array; } userId = createSelectOptions(jsonData); console.log(userId);

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter8: Arrays
Section: Chapter Questions
Problem 16E
icon
Related questions
Question

Javascript

createSelectOptions function

  • The function createSelectOptions should exist.

  • The function createSelectOptions returns undefined if no data parameter is provided.

  • The function createSelectOptions returns an array.

  • The function createSelectOptions returns an array with the correct length.

  • The function createSelectOptions returns an array of option elements.

  • The function createSelectOptions assigns the related user id to the value attribute of the options elements.

  • The function createSelectOptions assigns the related user name to the textContent attribute of the options elements.

createSelectOptions
a. Test users JSON data available here: https://jsonplaceholder.typicode.com/users
b. For testing (not in function) you may want to define users with the test data.
c. Receives users JSON data as a parameter
d. Returns undefined if no parameter received
e. Loops through the users data
f. Creates an option element for each user with document.createElement()
g. Assigns the user.id to the option.value
h. Assigns the user.name to the option.textContent
i. Return an array of options elements 

Here is what I have written but it is failing everything.  The only thing that passed was that I created a function with the correct name.

function createSelectOptions(users) {
  array = [];
  function getUser(item) {
    array.push(item.id);
  }
  data.forEach(getUser);
  return array;
}
userId = createSelectOptions(jsonData);
console.log(userId);
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT