+ 1

I Have problem with JavaScript ES6 Map & Set

So, in the exercise, it asks me to run a list of employees and add a new employee, but when I run the code, the result is the same as the output, but it's still wrong. I think it's because not only the result is correct, the code is also correct. I have no idea where I have to fix it. This is the code I try to run: function main() { var name = readLine(); var position = readLine(); let employees = new Map([ ["Richard", "Developer"], ["Maria", "SEO Specialist"], ["Tom", "Product Manager"], ["David", "Accountant"], ["Sophia", "HR Manager"] ]); //add the new pair to the map let employeeName="Robert"; let employeePosition="Developer"; employees.set(employeeName,employeePosition ); for (var i of employees.entries()){ let[name,position ]=i; //your code for the output console.log(name+" : "+ position ); } }

30th Sep 2024, 3:17 AM
Iris Aniele Pereira Redoval
Iris Aniele Pereira Redoval - avatar
2 odpowiedzi
+ 4
Iris Aniele Pereira Redoval name and position are already useful. No need for: let employeeName = "Robert"; let employeePosition = "Developer"; employees.set(employeeName,employeePosition); which defeats the purpose of the inputs. Robert: Developer was just an example. just use: employees.set(name,position); because you are adding the user inputs to the employee map, not Robert,Developer.
30th Sep 2024, 4:14 AM
Bob_Li
Bob_Li - avatar
+ 1
It worked! Thanks Bob_Li for helping me solve the exercise.
1st Oct 2024, 5:31 AM
Iris Aniele Pereira Redoval
Iris Aniele Pereira Redoval - avatar