FAQ: Debugging JavaScript Code - Locating Silent Bugs

This community-built FAQ covers the “Locating Silent Bugs” exercise from the lesson “Debugging JavaScript Code”.

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

Web Development

FAQs on the exercise Locating Silent Bugs

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

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!

Is it me or is this lesson (ironically) buggy? I can’t seem to get green from step 2.

4 Likes

I am having trouble deciding where to put the console.log() statement inside the if statement. I tried it before and after the word if but it didn’t work.
Where does this go?
console.log('Word value inside of if statement: ’ + word);

1 Like

Mine worked when I placed it at the start of the curly braces (of if statement) and before the return statement.

I’m having the same issue and I don’t know what it is asking…

I tried this too and it still isn’t working…

function capitalizeASingleWord(word) {
if (word.match(’ ')) {
console.log(word)
return null;
}

I found the solution to step 3 but also had problems. I think it’s incorrectly worded.

This is the first IF statement to succeed on #3

  if (!word.match(' ')) {
    console.log('Word value inside of if statement: ' + word);
    return null;
  }

Basically don’t fix the IF condition until step 4

2 Likes

Did anybody find a solution to the top post? I’m stuck on exactly the same thing right now.

2 Likes

Same issue… Tried many versions. Anyone knows how to do the step 2 to get it accepted?

Try checking the wording on question 1 again. Did you do something that it didn’t actually tell you to do?

function capitalizeASingleWord(word) {console.log(word)

  if (!word.match(' ')) {
    return null;
  }
  
  let firstLetter = word.charAt(0);
  const restOfWord = word.slice(1);
  
  firstLetter = firstLetter.toUpperCase();
  
  return firstLetter + restOfWord;
}

This should work…(I think its a bug)

for instructions no 2, put console.log(word) before the return null (if statement), not line 2 after the function. It’s so confusing

if (word.match(’ ')) {
console.log(word) ←
return null;
}

non functioning!!!help me!!

Hello,
The error is the “!” before the word.match, but don’t delete it in the first step.
Follow the steps:
Step 1: Just run it.
Step2: type console.log(word); before the if.
Step 3: copy the code console.log('Word value inside of if statement: ’ + word); before the if statement.
Step 4: delete the !

2 Likes

Hi, The following code seems to be working for me to move from Step#2 to Step#3.

  1. Just run the code in the first step.
  2. Add the console.log(word) immediately after the opening curly braces.
  3. Proceed as mentioned.
function capitalizeASingleWord(word) {console.log(word)
  
  if (!word.match(' ')) {
    
    return null;
  }
  
  let firstLetter = word.charAt(0);
  const restOfWord = word.slice(1);
  
  firstLetter = firstLetter.toUpperCase();
  
  return firstLetter + restOfWord;
}

// Should return "Hey"
console.log("capitalizeASingleWord('hey') returns: " + capitalizeASingleWord('hey')); 

// Should return null
console.log("capitalizeASingleWord('hey ho') returns: " + capitalizeASingleWord('hey ho'));

Solution for Step 2 to 3:
function capitalizeASingleWord(word) {

console.log(word)

if (!word.match(’ ')) {

console.log(word)

return null;

}

If you are stuck at step 3:

image

Delete the ! in step 3 to progress on to step 4, looks like they implemented a bug into the bug exercise.

1 Like

This right here is the solution. Is there anyway to pin this

When I have came to step 3 into Locating Silent Bugs, i could not do the task, but i wrote necessary ’ console.log(‘Word value inside of if statement: ’ + word);’. Only when I corrected the mistake at ‘if (!word.match(’ ‘))’ to ‘if (word.match(’ ‘))’ i can continue. In the step 4 i changed nothing, just ‘run’ and that`s it.

p.s. Sorry for my maybe bad English and maybe bad explain. :smiley:

2 Likes