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 trialJunior Aidee
Front End Web Development Techdegree Graduate 14,657 PointsI can't get the same result as in the video
I think I wrote the same as Guil did but I'm getting an error whenever I copy and paste into the console.
function getArea(width, length, unit) {
const area = width * length;
return ${area} ${unit}
;
}
getArea(10, 20, 'sq ft');
3 Answers
J A
Full Stack JavaScript Techdegree Student 4,646 PointsGlad you guys figured it out. For anyone else reading, I just wanted to provide clarification on why it seemed to only work when pasting the entire code with the function definitions and calls. If you start a web console in a fresh browser window without your code executing in the page, your function will not be defined in the console.
I imagine the error you probably got at the time was something like:
ReferenceError: Can't find variable: getArea
You had to paste the function definition for getArea()
in the console to define it, and only then could you call it. If I had to guess, you may have not updated the <script>
tag inside index.html
with js/multiple-args.js
and saved the file (happens all the time). If the <script>
tag was executed it would have defined the getArea()
function already so you can call it as many times as you want without a ReferenceError
.
Mytech T
Full Stack JavaScript Techdegree Student 1,427 PointsHi,
please use Markdown Cheatsheet Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.
when you use a template literals you should start with backticks like that.
return `${area} ${unit}`
Junior Aidee
Front End Web Development Techdegree Graduate 14,657 PointsThank you for your reply. The back ticks were there originally. I don't know why they disappeared after I copied and pasted the code to Treehouse Forum. My code seems to work fine now in the console after I pasted the entire code to the console. Thank you!
Tanner Funk
Full Stack JavaScript Techdegree Graduate 14,490 PointsI had the same issue! But it worked after pasting it all - including the function definition - into the console like you said. Thanks!