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);
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.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps