Finding errors in code with objects in JavaScript
In the following problems, some programmer has written code and may have made mistakes in it. You should check if the code does what is described. If the code does not work correctly, you need to fix the errors.
Задание 1
The code should output the element of the object:
javascriptlet obj = {x: 1, y: 2, z: 3};
console.log(obj[x]);
Задание 2
The code should output the object element by key from the variable:
javascriptlet obj = {x: 1, y: 2, z: 3};
let key = 'x';
console.log(obj.key);
Задание 3
The code should output the sum of the object elements:
javascriptlet obj = {x: 1, y: 2, z: 3};
let sum = obj[x] + obj[y] + obj[x];
console.log(obj);
Задание 4
The code should output the number of elements of the object:
javascriptlet obj = {x: 1, y: 2, z: 3};
console.log(obj.length);