Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Prakhar Patwa
11,260 Pointsi have a question regarding function
my js code is
function getArea(length , width)
{
var area = length * width ;
return "<h1>Area of <a href='#' style = 'color:red; text-decoration:none;' >Rectangle</a> is " + area + "</h1>";
}
document.write( getArea(34 , 22) );
=============================================
how to take a user input in this?
prompt("what is the length?");
prompt("what is the width?");
function returnValue(a){
return a ;
}
var echo = returnValue('My argument');
<!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>
2 Answers

Iain Simmons
Treehouse Moderator 32,289 PointsYou could either assign the return value of the prompt
function calls to two variables as Vitor Freitas recommended, or you could just call the getArea
function, passing in the prompt
function calls as parameters:
function myFunc(x, y) {
// function code here...
}
var x = prompt("What is x?");
var y = prompt("What is y?");
myFunc(x, y);
OR
function myFunc(x, y) {
// function code here...
}
myFunc(prompt("What is x?"), prompt("What is y?"));
Obviously the first is a bit easier to read and understand.

Vitor Freitas
3,579 PointsYou can do it this way :
var length= prompt("what is the length?"),
width = prompt("what is the width?");

Prakhar Patwa
11,260 Pointswill it be in the function or in the argument?
Prakhar Patwa
11,260 PointsPrakhar Patwa
11,260 PointsOkay got it.
Iain Simmons
Treehouse Moderator 32,289 PointsIain Simmons
Treehouse Moderator 32,289 PointsIf you feel that your question has been answered, please select an answer as the 'Best Answer' so that other Treehouse users know that this question has been resolved.