Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Note that
A[A.length]
is undefined too.i
is coming up as undefined because you're probably trying to use it outside of yourfor
loop. While normally it's not a problem, by declaring it aslet i=0
in your loop construction, you are limiting the scope ofi
to just that loop.For example:
The above code will result in an error with
i
being undefined.This code will not:
The above will declare
i
as a global variable, which isn't the best thing to do, but the code will work.The best practice is probably to use
var
like the following:The above code will limit the scope of
i
to just this function. So, if you were to check the value ofi
outside of this function, it would be undefined.let i
- is block scoped. That is,i
will only exist inside the current block of code, and any blocks within that block.var i
- is function scoped.i
will only exist inside the function in which it is declared.You're writing your solution in the sample test area, or you're writing the solution in the solution area? The 'A' variable doesn't exist until it's passed into your function.
I guess I'm having trouble understanding what you're doing. When you write a function, you set the variable names for the values that are passed into your function. In javascript, it looks like this:
And then that function can be called from elsewhere. Like this:
In this example, when
3
,4
, and5
are passed to theblah
function, the code inside the function will recognize thata == 3
,b == 4
, andc == 5
However, if outside your function, you try to call on one of those variables, they won't exist. So if you try this outside of your function code:
It won't print
3
to the console, it will printundefined
, becausea
doesn't exist outside of the function code.You shouldn't be writing in the sample text box unless you're trying to write your own tests. If you're just trying to come up with a solution, you should just stick to the solution box. The starter code looks like this:
Outside of the curly brackets of the function,
A
does not exist.