In the last video we were able to write out some code to fetch a single to do and printed out at the
terminal.
Now everything works pretty well but this console log right here is kind of ugly and it's hard to understand
in this kind of object format.
So in this video I want to pull off the I.D. title and completed flags and print them out in a nicer
format.
Kind of like a little report of sorts.
So let's try making some changes to our code base going to flip back over to my editor and to get started.
I'm going to first get a direct reference to the to do which is that data property right there.
So I'm going to essentially pull off that data property and assign it to a separate variable.
Again just to make it easier to work with.
So I'll say cons to do is response dot data.
Now we've got that to do we can pull off the I.D. the title and completed properties or assign them
to some temporary variables and then we can insert them all into a single string and console log that
string to essentially put together our report so I'm gonna pull off those three properties we just took
a look at.
So I'll say const idea is to do dot I.D. I'll get title as to do dot title and I'll say finished is
to do dot finished.
Like so now if you're looking at these three lines of code and thinking hey steven you just missed something
up right here.
That's totally fine.
Just bear with me for a second.
If you're looking at this code and you don't see anything wrong that's totally fine as well.
Again just bear with me for a moment.
So now underneath that we can start to print out a nice little report here.
So I'll do a console log to print out this as a nice little report.
I want to use a multi line string that is capable of using string templating.
So I want to kind of inject some variables into the string to do so we can use a template string just
as you might be familiar with from yes 2015.
So inside if you're going to put a set of back ticks remember these are back ticks.
It's the character to the left or the one on your keyboard.
They are not single quotes.
I'm going to turn this into a multi line string and I'll say something like the to do with Ida a colon
and I'll print out the idea
and I'll just like print out the title underneath I'll say as a title of dollar sign.
Title and I'll print out whether or not it is finished.
So I'll say something like Is it finished and I'll print in the finished variable like so.
All right so that's a little bit nicer to read report right there than the plain console log that we
had before.
So let's save this file and then attempt to run it at our terminal.
It's going to flip back over my terminal and I'll run the file in one step using T.S. node once again.
So I'll say T.S. node index dot T.S..
Remember we are feeding in the typescript file here.
We're not making use of the plain JavaScript file anymore so I'll run this command and sure enough I
end up seeing undefined undefined undefined.
Oh what's up with that.
That's kind of unexpected.
We just saw all that data appear correctly a moment ago when we did the console log.
So that means that we must have made a mistake somewhere in here.
So what is going wrong.
Well let's take a quick pause right here.
When we come back the next video we're going to make sure it's really clear what's wrong with this program.
And we're going to start to discuss how we can easily use typescript to avoid making the error that
we just made inside of here.
So quick pause and I'll see you in just a minute.