generate functionTue, 24 Jan 2023

A method that indicates how many employees are currently working in the company.

Script function employeeCount(employees) { // employeeCount is a function that takes in an array of people var count = 0; // Inside the function we'll set a variable called count to 0 for (var i = 0; i < employees.length; i++) { // Then we'll loop through the array of employees if (employees[i].isEmployed) { // If the person at the current index of our loop is employed count++; // Add 1 to our count } } // Lastly, return the total number of employees we counted. return count; } employees = [ {name: "Sam", isEmployed: true}, {name: "Sasha", isEmployed: false}, {name: "Derek", isEmployed: true}, {name: "Terri", isEmployed: true}, {name: "Michael", isEmployed: false} ]; employeeCount(employees); // 3

Questions about programming?Chat with your personal AI assistant