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 trial

JavaScript JavaScript Quickstart Functions Write a Function

Calling functions

How do you call a function and the specific syntax involved. I'm struggling on the last bit when I have passed the arguments thus calling the function.

script.js
function add10(2) {
  return 2+10
}
function add10()
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

Trent Ungard
Trent Ungard
10,533 Points

The issue with your syntax is that at time of declaration you shouldn't pass a fixed value into the function. When calling it after it is declared, you don't need to use "function". To fix your function, change the 2 in the parameter of your function and inside of your function to an x and when you call it, simply put "add10(valueYouWantToAdd10to)".

This would look like

function add10(x){ return x + 10; }

add10(8);

8 can be substituted in for any integer you would like to add. It will change the x out for the value you pass. Hope this answers your question. Cheers!