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");

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
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.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

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