All right.
Welcome back.
It's time for another exercise.
This time we're going to get some practice with the note command as well as some of the command line
basic commands and a nice review of javascript basics.
I've typed up the instructions.
Let me make this a little bigger and I'll go ahead and read out the exercise.
So using the command line create a file named Echo.
Yes.
Inside the file.
Write a function named Echo that takes two arguments a string and a number.
It should then print out the string number.
Number of times.
I know that's worded terribly.
I struggled for a while trying to come up with a better a better way of phrasing it but I think just
taking a look at the examples helps to illustrate it more than anything I could say.
So we call Ekko with a string.
In this case Ecko with three exclamation points and then a number 10 and that should print out echo
the string 10 times.
And if I called the Echo function with the string tater tots and then the number three it should print
out.
Tater tots three times.
So you need to define a file.
Echo J S.
Then define a function called echo inside the function and at the bottom of the function.
Add these two examples just that you have some test cases and then the last thing you need to do is
run the contents of that echo japes file using Knode as always Pozza video right now.
Go ahead do this on your own and then I'll be back in a little bit with a solution.
Let's get started.
So we need to create a file named Echo.
Yes so I'm going to do that right here.
Touch echo.
Yes and then inside the file.
Write a function named Echo.
So let's open up the file can see it here open
and the first thing that we need to do is write a function named Echo that takes two arguments.
Let's do that now.
Function.
I go and take an argument string and no just like that it should print out the string number number
of times.
So we know we need to have a cancel but log string in there somewhere and then we need to repeat this
line cancel belt log number or Nome number of times.
We could either use a while loop or a for loop to do this.
I definitely prefer for loops so we'll do that here.
So for and we can do this multiple ways we can start with.
We can start with a variable equal to zero and go all the way up until we can start with a variable
equal to numb and count backwards down to zero.
We can start at an arbitrary number like 30 and then keep going until we hit 30 plus now.
But I'm just going to start with I equal to zero.
And then when do I.
Is less than numb.
And the reason that it's less than is that I'm starting at zero.
If I wanted to I could start at 1 and go less than or equal to numb and then I'll just add one to I
.
And we're never going to use the variable all that we're doing is putting a constant log inside so we
don't use.
We're just every time going to cons. about lug strength.
Now let's copy these two examples and just put them at the bottom and let's go ahead and try running
this.
So we need to save the file first and then we need to go to our command line make sure we see the file
.
I go through yes and then we run it with the command node.
Echo.
Yes and there we go.
Let's see we have one two three four five six seven eight nine ten echoes and then we get tater tots
three times.
That's all we needed to do in the next video.
There's one more exercise that's a little bit more challenging.
Using an array