Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChadwick Savage
11,919 PointsWhy does the console log undefined when running the third function?
const addToTen = num => 10 + num;
const divideUs = (num1, num2) => num1/num2;
const printMyName = (test) => console.log(test);
console.log(addToTen(5)); console.log(divideUs(10,5)); console.log(printMyName('Chad'));
Console:
treehouse:~/workspace$ node convert.js
15
2
Chad
undefined
treehouse:~/workspace$
2 Answers
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsHey friend Chadwick Savage , you have two mistakes here .
First , you have already defined console.log()
statement within your printMyName function , and you are using it outside too.
Second , you have used =
operator in between function name and parenthesis , which should not be there
const printMyName(test) => console.log(test);
Just call the function with your desired name like this printMyName('Chad')
Hope it helps :)
Magnus Martin
44,123 PointsAakash is right there. I initially made the same mistake when copying my console.log statement. The printMyName function already logs to the console but returns nothing. So an extra undefined gets logged.
Nelson J
7,411 PointsThanks I was having the same problem.