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 trialAgnes Caringal
6,239 PointsHow can I make this challenge!...anyone can help me with function code..
what's wrong with my answer :(
function returnValue () {
var value = Math.floor(Math.random()*6) +1;
return returnValue
}
<!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>
9 Answers
Ted Sumner
Courses Plus Student 17,967 PointsThis code just passed for me:
function returnValue($value) {
return $value;
}
Ted Sumner
Courses Plus Student 17,967 PointsCode for passing second part:
function returnValue($value) {
return $value;
}
var echo = returnValue('My argument');
It is important to learn how to quote code. Use three back ticks (`) located on the upper left of your keyboard followed by the language without a space in between. I usually have to double space between the text above and the `. Insert your code on the next line. Then on the line after your code, three more ` to close it.
Agnes Caringal
6,239 Pointsthank you so much, any tips on JS? i have a lot of things to learn :)
Ted Sumner
Courses Plus Student 17,967 PointsLooking at what you posted, my overall tip is to pay attention to the little details. They are everything in any type of programming. For the Treehouse challenges, take your time to read the instructions very carefully. If you don't you will not pass the challenges. The final tip is to take the time to deploy your own solutions implementing what you learned as you go along. It will stick in your mind better. Personally, I need to deploy some sites with some custom JavaScript to get it in my mind.
At the bottom of the answer is an option called Best Answer. Please click that because it signals that your issue was answered successfully.
Tajul Sharby
3,463 Pointshey thanks for this! I didn't manage to pass the second challenge without your help.
Ted Sumner
Courses Plus Student 17,967 PointsWhat jumps off the page to me is you have no semicolon after your return line. I will have to retake the challenge to see if anything else is wrong. Let me know if the semicolon solves it. If not, I will redo the challenge.
Agnes Caringal
6,239 Pointsactually this is the challenge question # 1 : Here's a simple challenge: create a function named returnValue() that accepts a single argument, then returns that argument. This isn't a useful function, but we want to make sure you know how to create a function that can accept information when it is called.
Agnes Caringal
6,239 PointsI put the semicolon, but bummer shows like this.
Bummer! Make sure you return the argument that's passed into the function. In other words type return
, a space, and the parameter name.
Ted Sumner
Courses Plus Student 17,967 PointsYou need a variable in the ().
Agnes Caringal
6,239 Pointsfunction returnValue (upper) { var value = Math.floor(Math.random()*6) +1; return returnValue; }
Agnes Caringal
6,239 Pointsfunction returnValue (upper) { var value = Math.floor(Math.random()*6) +1; return returnValue; }
Agnes Caringal
6,239 Pointsfunction returnValue (upper) { var value = Math.floor(Math.random()*6) +1; return returnValue; }
Agnes Caringal
6,239 Pointsfunction returnValue (upper) { var value = Math.floor(Math.random()*6) +1; return returnValue; }
Ted Sumner
Courses Plus Student 17,967 Pointsvariables have to have a $ in front.
also, refer to the Markdown Cheatsheet for formatting quotes.
Ted Sumner
Courses Plus Student 17,967 PointsDid you add the semicolon?
Ted Sumner
Courses Plus Student 17,967 PointsIf this is answered, please mark is so.
Agnes Caringal
6,239 Pointsso meaning when they said one argument, always inside the () of a function named?
Ted Sumner
Courses Plus Student 17,967 PointsFor a function to accept an argument, there must be a variable in the (). One variable for each argument that needs to be passed into the function. Then you need to call the function. Did you pass that part of the challenge?
Agnes Caringal
6,239 PointsNow that you've created the returnValue function, call it, by passing it a literal string value -- a series of characters in quote marks like this: 'My argument'. Store the results of the function in a variable named echo.
answer :
function returnValue($value) { var echo ('My argument'); return $value; }
bummer : Oops! It looks like Task 1 is no longer passing.
Agnes Caringal
6,239 Pointsthank you so much :)
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsTo explain: Create a function:
function returnValue
That accepts one argument:
($value)
And returns the value:
return $value;
The code challenges are very picky and require exactly what they ask for.
Agnes Caringal
6,239 PointsAgnes Caringal
6,239 Pointsyeah I passed also, thanks, i was confused with the second challenge, Im kinda confused with this one also :(