Monday, January 9, 2012

Codecademy - Functions in Javascript Lesson 2 - Argument Types, part 1

I just had a nice little hour of fun with Codecademy but wound up taking too much time on this problem: http://www.codecademy.com/courses/functions_in_javascript/1#!/exercises/2

Here's a hint (and then an answer) to help you figure this one out.  The unstated goal is to see the output of cube("test"). How can you do that?

Highlight the lines below for some additional help:

Perhaps you could send the results of that call to the console log?


Line 6 in the example shows how to put the output of cube(5) in the console ;)

5 comments:

Anonymous said...

I have been stuck on this for a month, I left feedback on the website but never got an answer. Based on your hint I tried:

console.log(cube("test"));

I get:

NaN
Oops, try again.

I really don't get why you even have to do that, the exercise simply states to run the code as is. I have no idea if it's a glitch and it's driving me crazy. I completed the next part anyway but I have a gap now showing the lesson as incomplete.

Panicswitch said...

console.log(cube("test"));

I just cut and pasted what I used to complete this section - which I wouldn't have been able to do without the hint above, so thanks for that.

Anon, maybe you'd changed something else in the earlier code. Perhaps re-load the default and try again.

Fred said...

Comment out (or delete) the final line of code.

Anonymous said...

@Fred Bingo! That worked! The worrying thing is it works for console.log(cube("test")); as well as console.log(cube(5)); as long as the final line is commented out.

Although it passes the lesson it has just served to confuse rather than educate me. Is this a glitch, are their instructions wrong, or was the starting code wrong? I thought the point of the exercise was to run the code to show that the string "test" is not a number and therefore can't be cubed.

Prior to this I had tried it in multiple browsers, logged out and back in again, reset the code etc... and nothing worked.

Anonymous said...

I just hit run and it was correct. I am having problems with next argument. I cannot get it to reset to try again. I signed off and back on and it still has my mistake but I want to start over. Any suggestions?