Skip to content

Instantly share code, notes, and snippets.

@ross-u
Last active January 16, 2021 13:24
Show Gist options
  • Save ross-u/b83dd87e4230a34854022155a8bdea3a to your computer and use it in GitHub Desktop.
Save ross-u/b83dd87e4230a34854022155a8bdea3a to your computer and use it in GitHub Desktop.
JS | Arrays - Employees - Exercise

JS | Arrays

Arrays | Employees - Exercise



For this exercise you can use Repl.it or your code editor.


Task 1

Create an array of employees containing the following strings:

"Bob", "Sarah", "Anna", "Martha", "John", "Ben", "Nidia".

After you finish, console.log the employees array.

console.log(employees);

Task 2

Using the method push add new strings representing the new employee names: Adriana, Gabriel, Mia .​

console.log the employees array.

console.log(employees);

Task 3

Using method pop remove the last employee Mia and save it in a string named mia.

console.log the employees array and variable mia.

console.log(employees);
console.log(mia);

Task 4

Let's promote Martha to be the new manager! Create a new array called managers using the method splice . Make sure to remove only Martha from the employees array.

We can't afford to promote just anyone! 👷

console.log the employees and managers array.

console.log(employees);
console.log(managers);

Task 5

Let's promote another employee. Using the method shift remove the first employee from the employees array and add him to the managers array. Yay! Martha is not alone.

console.log the employees and managers array.

console.log(employees);
console.log(managers);

Task 6

As the last step print the length of managers and employees arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment