For this exercise, you can use Repl.it or your code editor.
Using the array of users given in the data.js
file, go ahead and finish the tasks as specified in the task list. You should have your solution saved in the index.js
file.
- Fork this repo
- Then clone this repo.
- Upon completion, run the following commands:
$ git add .
$ git commit -m "done"
$ git push origin master
- Create Pull Request so your TAs can check up your work.
Create a function getFirstNames()
and, using for...of loop, iterate over the usersArray and push all the first names into a new array userFirstNames
.
Create a function getFullNames()
which will return an array of strings where each string will represent the full name of each user from the usersArray.
Steps:
- using for...of loop iterate over the usersArray and
- using ES6 string interpolation create a string containing full name (tip: access each object via
dot notation
), - push that string into a new array
userFullNames
.
Create a function getUsersCreditDetails()
to grab each user's first and last name and their balance.
Steps:
- Using
for...of
loop iterate over theusersArray
; - Destructure
firstName
,lastName
andbalance
from each user object to create new variables; - After destructuring create a new object using object literal (only name of variable) consisting of
firstName
,lastName
andbalance
. Check the following example:
const userDetails = {
firstName,
lastName,
balance
};
- Push each new object into a new array
usersCreditDetails
Create a function genderView()
which should return two arrays new arrays femaleUsers
and maleUsers
. Depending on the gender, fill them with strings containing users' first and last names.
Create a function genderCount()
that should use the returned object from the previous function and print how many females and how many male users there are.
Check the index.js
to see what should be expected output.
Create a function promo20()
to find all users whose balance is greater than 20000 and send them a personalized message offering some promotion.
Check the index.js
to see what should be expected output.
Create a function addActive()
which should loop through the usersArray
and add a new property isActive
with a value true
to all users (hint: each user in the usersArray
is represented with object and you could use ...
with objects 😉 ).
Check the index.js
to see what should be expected output.
Happy coding! ❤️