Search for errors in the code
In the following tasks, some programmer has written code and maybe have made errors in it. You should check if the code perform what it is described. If the code does not work correctly, you need to fix the errors.
The code should find the sum of numbers:
javascriptlet num1 = 1;
let num2 = 2;
console.log('Sum: ' + num1 + num2);
The code should find the sum of numbers:
javascriptlet a = 1;
let b = 2;
console.log(a + b + c);
The code should find the sum of the digits of the number:
javascriptlet num = '123';
let sum = num[0] + num[1] + num[2];
console.log(sum);
The code should output the first digit of the number:
javascriptlet num = 123;
console.log(num[0]);
The code was supposed to print the
number 1 to the console,
but it prints 0:
javascriptlet a = 0;
console.log(a++);
The code should output the number of digits in the number:
javascriptlet num = 123;
console.log(num.length);
The code should obtain the number of seconds in a day:
javascriptlet a = 24 / 60 / 60;
console.log(a);
The code should output the number of digits in the number:
javascriptlet num = 123;
let str = String(num);
console.log(num.length);
The code should output the last digit of the number:
javascriptlet num = 123;
let str = String(num);
console.log(num[num.length]);
The code should output the number of digits in the number:
javascriptlet num = 123;
let str = String(num);
console.log(str.lenght);
The code should output the last digit of the number:
javascriptlet num = 123;
let str = String(num);
console.log(str[str.length]);
The code should find the sum of the numbers:
javascriptlet a = '123';
let b = '456';
let s = Number(a) + String(b);
console.log(s);