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 trialJustin Ezor
2,193 PointsI have no idea how to do the sum of two floats
I'm doing a code challenge and its asking me to implement a function that returns the sum of two floats. then it talks about arguments. Help!
1 Answer
Ben Hopkins
Full Stack JavaScript Techdegree Student 2,348 PointsFirst you need to define the return type for the methed, which Is float.
Then name the function and add two argument, these also need to be floats. This will now look like this :
float addTwo(float a,float b){
}
You then need to tell the function what to do with the arguments you are passing it, in this example you want it to return the sum of the two arguments. This looks like this:
return a + b;
Then combining the two parts of what you have you get this:
float addTwo(float a,float b){
return a + b;
}
Ben.