Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

I have an error inside my simple javascript code, I want you to fix it. The code is simple. The code is supposed to print an array with 10 elements, but when it comes to one element inside the array, it is supposed to concatenate a string value

The problem with my code is it is printing all elements of the array, but it is not concatenating a string to one element. The problem is inside my print_array_changed function

Generally, the code is required to print all elements with one element having a concatenated string. Look inside the print_array_changed function and fix it to attain the desired goal

Code 

// create an array and assign values inside it
 
            const Employees = [
                "JACK",
                "JILL",
                "Homer",
                "Lisa",
                "Bart",
                "Marge",
                "Burns",
                "Maggie" ,
                "Amy",
                "Bill",
            ]
 
// This function prints all elements inside the employee array but 
// concatenates a string to one element
 
 function print_employees_changed (Employees, best_employee) {
                for (let index = 0; index < Employees.length; ++index) {
                    if (Employees[index]== best_employee) {
                        let the_best_employee = "Employees of the month is" + Employees[index];
                        console.log (the_best_employee);
                       }
                   else {
                       console.log (Employees[index]);
                    }
                  }
                }
 
  // Make a function call to print_employees_changed and
  // print elements inside the employee array with a string
  // added to one element
                 
            console.log ("Calling print_employees_changed function")
            print_employees_changed(Employees, "Jack");
Expert Solution
Check Mark
Step 1

Since the case mismatches the output produced is wrong. So the idea is to make both the string to lowercase compare it if equals then print.

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education