Chrome dev tools console

TL;DR: console.log() isn’t supported by FreeCodeCamp, I learned to use Chrome dev tools’ console to log to console and view elements of my code.

Today I learned how to use the console in Chrome dev tools to log details of my project. FreeCodeCamp doesn't have any support for the console.log() function in its output view. When I wanted to check the output of variables or other elements at some point during a project, I didn’t know what to do. I had used console.log() on Codecademy which did support console.log().

I was working on an algorithm challenge. I needed to test whether a given string ended with a given sub-string. One requirement was that we couldn't use the .endWith() method. We had to use the .substring() or .substr() method. I chose .substr(). It made more sense to me.

There were multiple test cases. Two example cases would be: does “I need a treat” end with “t”? Does “I have a car” end with “hello”? In my example the string is “I need a treat” and the target is “t”. I created a variable called test to hold the .substr() value. Then I needed to create the .substr() value to put into test. Then it was just a matter of comparing the target value against the test value and returning true or false for each example to complete the challenge.

The problem came with the .substr() parameters. I knew what I WANTED it to do, but I wasn’t sure what it was actually capturing. I knew I would have to experiment a bit, seeing as I had never used it before, and needed to use variables instead of real number values so that the same code would work on multiple cases. I wanted to use console.log() to show what was actually being returned so that I could adjust the parameters accordingly.

I googled how to use the console.log() on Freecodecamp and why it didn’t work like it did on Codecademy, and what I found was that it wasn’t supported by FCC. I also found that the built in Chrome dev tools window had a console that would log everything.

I was able to insert a console.log() method into my code and use the dev tools console to see what was being returned by my .substr() parameter variables, and that made it so that I could adjust the parameters to complete the challenge!

Heres my code:

function confirmEnding(str, target) {
var test = str.substr(str.length-target.length, target.length);
console.log(str.length,target.length, test, target);
if (test === target){
return true;
} else {
return false;

confirmEnding("Bastian", "n");
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.