admin管理员组文章数量:1122846
I’m preparing for a coding bootcamp and working through JavaScript exercises as part of the application process.
I’ve been tasked with:
Write a function called addNums that will add 1 and 2 in an expression and assign the result to a variable named mysteryNumber.
Here’s the code I’ve written so far:
function addNums(a, b) {
return a + b;
}
const mysteryNumber = addNums(1, 2);
console.log(mysteryNumber);
Issue
When I test this in the debug console, it works perfectly and logs 3. However, when I try to submit my solution, I get the following error message:
"Remember to include parentheses"
I’m not sure what part of my code this message is referring to. I’ve included parentheses in the function call and the function itself.
What I’ve Tried
- Double-checked the syntax of the function.
- Ensured that parentheses are included when calling the function.
- Reviewed online examples of similar problems, but I’m still stuck.
Question
What does "Remember to include parentheses" mean in this context? Is there something wrong with how I’m calling or defining the function? Any guidance would be greatly appreciated!
I’m preparing for a coding bootcamp and working through JavaScript exercises as part of the application process.
I’ve been tasked with:
Write a function called addNums that will add 1 and 2 in an expression and assign the result to a variable named mysteryNumber.
Here’s the code I’ve written so far:
function addNums(a, b) {
return a + b;
}
const mysteryNumber = addNums(1, 2);
console.log(mysteryNumber);
Issue
When I test this in the debug console, it works perfectly and logs 3. However, when I try to submit my solution, I get the following error message:
"Remember to include parentheses"
I’m not sure what part of my code this message is referring to. I’ve included parentheses in the function call and the function itself.
What I’ve Tried
- Double-checked the syntax of the function.
- Ensured that parentheses are included when calling the function.
- Reviewed online examples of similar problems, but I’m still stuck.
Question
What does "Remember to include parentheses" mean in this context? Is there something wrong with how I’m calling or defining the function? Any guidance would be greatly appreciated!
Share Improve this question asked Nov 21, 2024 at 12:22 808Squad808Squad 115 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1I think the task itself is kind of confusing...
I can only (logically) infer that it wants this answer:
// Write a function called addNums
function addNums ( expression )
{
// that will add 1 and 2 in an expression
const result = expression + 1 + 2;
// and assign the result to a variable named mysteryNumber
mysteryNumber = result;
}
// TESTING:
addNums('SomeString');
console.log(mysteryNumber);
It's still possible to reduce the code to this:
function addNums ( expression )
{
mysteryNumber = (expression + 1) + 2;
}
// TESTING:
addNums('SomeString');
console.log(mysteryNumber);
The parentheses are optional in mysteryNumber = (expression + 1) + 2;
.
PS.: I don't know if the expected answer is this (by who imputed this task), but the logic of the task requires this answer.
NOTE:
The task is not requiring to test the function, so maybe you should discard anything that is not the function in your answer.
The task is not requiring that the function must return the result.
The
expression
parameter is not required by the task and is optional as its value could be defined in an outer context (for example the global context wheremysteryNumber
is or should be defined).I don't think that "Remember to include parentheses" is actually an error, but rather a hint generated by the system that dumbly thinks you should add parentheses to fix your answer.
This answer is probably not what the task actually expects you to answer.
Here in my country, dubious tasks in tests must be eliminated on demand. For example, if a task is "write 1 + 2 in full" and you answer "one plus two", but the expected answer was "three", then you can demand to cancel that question because it's dubious, regardless if your answer was right or wrong, they must cancel the task and redistribute the points given to each task or give full marks for that task specifically... I don't know if its the case for this task or even if its feasible where you are.
版权声明:本文标题:How do I fix the "Remember to include parentheses" error in my JavaScript function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310939a1934558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
addNums()
, and then have your function not accept any parameters and instead justreturn 1 + 2;
(since the question doesn't specify the function needing to accept arguments) – Nick Parsons Commented Nov 21, 2024 at 12:26const
is a constant, not a variable, usevar
orlet
instead. – Martin Zeitler Commented Nov 21, 2024 at 12:41mysteryNumber
does not change here, soconst
is fine. – mykaf Commented Nov 21, 2024 at 14:22