13/03/2023 8:42 am
Topic starter
Notifications
Clear all
I want to print the sum of 5 + 15 but the output is 510 can someone help please ?
0
😩 😭 😱Â
function addNumbers(num1, num2) { return num1 + num2; } let result = addNumbers(5, "10"); console.log(result);
Â
Answer
Add a comment
Add a comment
2 Answers
1
15/03/2023 3:38 pm
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);
Add a comment
Add a comment
0
16/03/2023 1:01 pm
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 😀 😎Â
Add a comment
Add a comment
Forum Jump:
Related Topics
-
What is a primitive programming language ?
2 years ago
-
How can we use AI in debugger?
2 years ago
-
What is syntax error ?
2 years ago
-
What is an array ?
2 years ago
-
What is an IDE ?
2 years ago
Forum Information
- 14 Forums
- 1,837 Topics
- 5,053 Posts
- 0 Online
- 1,079 Members
Our newest member: Tyronenodub
Latest Post: loli
Forum Icons:
Forum contains no unread posts
Forum contains unread posts
Topic Icons:
Not Replied
Replied
Active
Hot
Sticky
Unapproved
Solved
Private
Closed