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:
let num1 = 1;
let num2 = 2;
console.log('Sum: ' + num1 + num2);
The code should find the sum of numbers:
let a = 1;
let b = 2;
console.log(a + b + c);
The code should find the sum of the digits of the number:
let num = '123';
let sum = num[0] + num[1] + num[2];
console.log(sum);
The code should output the first digit of the number:
let num = 123;
console.log(num[0]);
The code was supposed to print the
number 1
to the console,
but it prints 0
:
let a = 0;
console.log(a++);
The code should output the number of digits in the number:
let num = 123;
console.log(num.length);
The code should obtain the number of seconds in a day:
let a = 24 / 60 / 60;
console.log(a);
The code should output the number of digits in the number:
let num = 123;
let str = String(num);
console.log(num.length);
The code should output the last digit of the number:
let num = 123;
let str = String(num);
console.log(num[num.length]);
The code should output the number of digits in the number:
let num = 123;
let str = String(num);
console.log(str.lenght);
The code should output the last digit of the number:
let num = 123;
let str = String(num);
console.log(str[str.length]);
The code should find the sum of the numbers:
let a = '123';
let b = '456';
let s = Number(a) + String(b);
console.log(s);
The code should find the sum of the numbers:
let aaa = 1;
let bbb = 2;
let ccc = 3;
console.log(aaa + bbb + ссс);