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");
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
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
This is a popular solution!
Step by step
Solved in 2 steps with 2 images