FAQ: Code Challenges: JavaScript Fundamentals - reportingForDuty()

This community-built FAQ covers the “reportingForDuty()” exercise from the lesson “Code Challenges: JavaScript Fundamentals”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

FAQs on the exercise reportingForDuty()

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

When making an error in the string that is returned, the error message in the buttom suggests a different string to be returned than the excercise.

string suggested in excercise and the one to actually match with :
‘Private Fido reporting for duty!’

string suggested in error message:
‘Private Fido reporting for duty, sir!’

The SCT will accept the example given in the instructions, though it does seem to be written rather oddly…

        expect(reportingForDuty('Private', 'Fido'), "Your function should accept two strings as arguments and return a string in the following format: 'rank lastName reporting for duty, sir!'").to.equal('Private Fido reporting for duty!')

I literally copypasted the solution into the exercise, after resetting, and it still wouldn’t pass me. Can anyone help?

My code: (again, taken directly from the solution)

const reportingForDuty = (rank, lastName) => `${rank} ${lastName} reporting for duty!`

console.log(reportingForDuty('Private', 'Fido'))

Addendum: This exercise must be bugged. I tried logging Hello World! to the console and that didn’t even work. This is the only exercise I’ve done in Codecademy that’s been impossible to finish.

The exercise needs to have its instructions updated, because it does not accept what is written in the instructions like you said, it gives me the error

Suggest try to remove the comma after RANK.

I did, it still gave me an error, the solution of course automatically let me move on, but i bet would still give me an error if i tried to run it cause my code matched the solution at the end, But with the comma being removed and the “, sir!” added it still gave me an error, so something is wrong with this exercise, and the next one too.

Mine passed with, Private Fido reporting for duty!

interesting, as did mine… Sorry :slight_smile: but the error message needs to be changed to match the instructions at least.

1 Like

My passed answer’s here:

const reportingForDuty = (rank, lastName) => {
  return `${rank} ${lastName} reporting for duty!`;

My question is, why can’t I change “return” to “console.log(…)” ? I used console.log first but couldn’t pass.
These 2 always confuse me…

The return gives data back to the program. It can be assigned for later use or used in place by another function, or just logged at the caller, rather than in function scope. return gives the programmer options for further use of the data once the function data is lost.

const foo = () => {
   // all the data in here is scrubbed (garbage collected) 
   // when the function is exited.
1 Like


return is a pipeline connected to every caller and carrying the output of a function. Just by calling a function, that point in the program is added to the call list, and becomes part of the pipeline. Delivery is more discreet, though, as it is only to the caller.

The key point here is that a function is accessible to its own scope and below. Regardless what scope the caller, the function will render a return value to that scope from whatever scope it happens to be in.

1 Like

In the function expression should i use const or let keyword ?

By using const, we cannot assign a new value or object to the variable. It will keep your function from being overwritten/destroyed.

const my_func = function () {
    // this function is an immutable_object

let my_func = function () {
    // this function is not an immutable_object
1 Like

simple and great explanation as usual, thank you :heart:

1 Like

The code I came up with is executing fine but the lesson check won’t accept it. Just trying to figure out what’s wrong with it.

const truthyOrFalsy=()=>{
let numberOfPpl=0
if (numberOfPpl){
return true
return false


The function truthyOfFalsy is what we know as a predicate function. It checks the parameter and returns a boolean. For this exercise, the operative word is parameter. We need to pass a value or expression to the function, not create a value inside.

const is_truthy = expr => expr ? true : false;

console.log(is_truthy(0))    //  false
console.log(is_truthy(1))    //  true

console.log(is_truthy(""))    //  false
console.log(is_truthy(" "))    //  true

Predicate (mathematical logic) - Wikipedia

Why this kind of function declaration is not allowed in this exercise? Are there any reasons using the arrow function expression is better?

function reportingForDuty( rank , lastName ){
  return `${rank} ${lastName} reporting for duty! `

What would be the best way to apply capitalization to either the first letter only of the inputs, or to the entire inputs (which I’m guessing would still be .toUpperCase)?

Hi everyone my code executes fine but is not accepted. The reason given is not well explained. Can anyone tell me what might be wrong with my code? Thanks in advance!

function reportingForDuty (rank, lastName) {
console.log (${rank} ${lastName} reporting for duty!)
reportingForDuty(‘Private’, ‘Fido’);

console shows : Private Fido reporting for Duty!

The message that they gave me was :

Your function should accept two strings as arguments and return a string in the following format: ‘rank lastName reporting for duty!