본문 바로가기

Programming/JavaScript

Functions Calling Other Functions

function cutFruitPieces(fruit) {
    return fruit * 4;
}

function fruitProcessor(apples, oranges) {
    const applePieces = cutFruitPieces(apples);
    const orangePieces = cutFruitPieces(oranges);

    const juice = `Juice with ${applePieces} piece of apple and and ${orangePieces} pieces of orange.`;
    return juice;
};

console.log(fruitProcessor(2, 3));
// prints Juice with 8 piece of apple and and 12 pieces of orange.

하나의 function에서는 한 가지 역할만 하는게 좋음

여기선 function마다 역할을 세분화해서-

하나의 function 안에서 필요한 다른 역할을 다른 function을 call함

'Programming > JavaScript' 카테고리의 다른 글

Coding Challenge #1 - who's win?  (0) 2022.09.09
Reviewing Functions  (0) 2022.09.05
Arrow Functions  (0) 2022.09.03
Function Declarations vs. Expressions  (0) 2022.09.03
Activating Strict Mode  (0) 2022.09.02