javascriptbeginner10 minutes
Fix the Bug in a Simple Function That Adds Two Numbers
Identify and fix the bug in a JavaScript function designed to add two numbers and return the result. This challenge tests understanding of basic function syntax and return statements.
Challenge prompt
The following function is intended to take two numbers as input parameters, add them together, and return the sum. However, it currently does not work correctly. Find and fix the bug so the function behaves as expected.
Guidance
- • Check the syntax of the function, especially the return statement.
- • Verify if the function parameters are used correctly within the function body.
Hints
- • Is there a missing keyword or syntax error in the function?
- • Make sure the function actually returns the result of the addition.
Starter code
function addNumbers(a, b) {
let sum = a + b;
sum;
}Expected output
addNumbers(3, 4) should return 7
Core concepts
function syntaxreturn statement
Challenge a Friend
Send this duel to someone else and see if they can solve it.