+ 1
Why only include [0] and [1] in the answer?
5 employee names are stored in Map in the program you are given. Their names are set as keys and their positions as values. The company is hiring one more employee. The program should take the name and the position as inputs and store them in the existing map. Complete the program to perform that operation and output to the console the list of employees in the format shown in the sample output. Sample Input Bob Developer Sample Output Richard : Developer Maria : SEO Specialist
4 Antworten
+ 2
i[0] represents the employee names and i[1] represents the employee positions, where would you need i[2] - i[4]?
+ 1
https://code.sololearn.com/cXjNl25C17ak/?ref=app
I answered correctly but not on the first try. Initially, I added console.log(i[0] + “ : “ + i[1] + i[2] + i[3] + i[4]). Why only the first two should be added?
+ 1
Seb TheS I was thinking about it incorrectly as entering an array where index 0 is the first pair (Richard, Developer). Index [1] : Maria, SEO, etc.
Thank you for clearing that up! Sure makes sense now.
0
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"]
]);
//your code heres goes
employees.set(name,position)
for(var i of employees.entries()){
console.log(i [0] + " : " + i [1])
}
}