Joesson
New Coder
Hello, newbie here. Why does this code tell me that lastElement is undefined?
I also tried a different version of it, which returns as undefined as well:
I thought that the contents of 'lastElement' would be defined by the user when passing the argument, and so by then it would be defined? What am I missing?
I am trying to return the last element of the array, when the function is called.
Thanks!
JavaScript:
function lastElement ([Good, Bad, Ugly])
{
let index = lastElement.indexOf('Ugly');
return index;
}
lastElement('Loafy', 'Boafy', 'Goafy');
I also tried a different version of it, which returns as undefined as well:
JavaScript:
function lastElement ([val1, val2, val3])
{
let index = lastElement[lastElement.length -1];
return index;
}
lastElement('Loafy', 'Boafy', 'Goafy');
I thought that the contents of 'lastElement' would be defined by the user when passing the argument, and so by then it would be defined? What am I missing?
I am trying to return the last element of the array, when the function is called.
Thanks!