카테고리 없음
[자바스크립트] 코드아카데미 정답풀이 Introduction to Functions in JS (9/13)
tomato23
2014. 7. 22. 17:13
주제는 두개의 인수를 전달받는 함수 만들기다.
지정된 함수의 이름(perimeterBox)에서 알 수 있듯이 사각형의 둘레를 구하는 함수를 만드는 것이 이번 테스트의 목적이다.

http://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/1?curriculum_id=506324b3a7dffd00020bf661#
Functions with two parameters
So far we've only looked at functions with one parameter. But often it is useful to write functions with more than one parameter. For example, we can have the following function: var areaBox = function(length, width) {
return length * width;
};
With more than one parameter, we can create more useful functions
To call a function with more than one parameter, just enter a value for each parameter in the parentheses. For example, areaBox(3,9); would return the area of a box with a length of 3 and a width of 9.
- Write a function called
perimeterBox that returns the perimeter of a rectangle.
- It should have two parameters.
- One formula for perimeter is
length + length + width + width;
- Call the function and pass in any value for length and width you like.
?
Stuck? Get a hint! Hint
Remember for functions, the parameters go in parentheses ( ) . And the block of reusable code goes in curly brackets { } . |