Lesson 10- Array Positions. Correct output but error


#1

So when i run my code i get:
31.
I tried refreshing the page but that doesn't work. Curious if i have something extra there that isn't needed, or im missing a tiny character somewhere in my console.log.
Thanks so much for your help in advance!

This is the error message i'm getting:
Oops, try again. Alas, you should have printed 31, as that is the 4th element!

This is what my code is: 
// Practice array!

var junkData = ["Eddie Murphy", 49, "peanuts", 31];

console.log=(junkData[3])

#2

I figured it out! Didn't need the "=".
Though earlier when i tried to enter it without the "=" it didn't print anything at all.
Just a error with the lesson?


#3

No. You corrupted JavaScript's Console object by reassigning the .log method a new value.

console.log = anything

will destroy that method. It will not longer work as a function since it is not a function (unless 'anything' happens to be one).

We never assign output to the console, we pass it as a function argument.

console.log(anything);

anything may be just that. Anything. A string, a number, an expression of any sort, even a function call.

var foo = function (bar) {
    return "foo" + bar;
};
console.log(foo('bar'));      // foobar

console.log(foo.toString());  // function (bar) {\n    return 'foo' + bar;\n}

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.