I want to print the…
 
Notifications
Clear all

I want to print the sum of 5 + 15 but the output is 510 can someone help please ?

2 Posts
3 Users
1 Likes
374 Views
0
Topic starter

😩 😭 😱 

function addNumbers(num1, num2) {
  return num1 + num2;
}

let result = addNumbers(5, "10");
console.log(result);
 
Topic Tags
2 Answers
1

You are adding a number and a string, so it is concatenating the string instead of numerically adding it. To add 5 and 10, pass the values as 

let result = addNumbers(5, 10);
0
function addNumbers(num1, num2) {
  return num1 + num2;
}

let result = addNumbers(5, +"10");
console.log(result);

replace the code with this ,and you’re set to go 😀 😎 

Share: