완벽한 장면
2024. 4. 10. 17:07
ex. 기분에 따라 하는 행동 출력하기
function mood(state) {
if (state === "good") {
// 기분 좋을 때 하는 동작
sing();
} else {
// 기분 나쁠 때 하는 동작
cry();
}
}
function cry() {
console.log("액션 : CRY");
}
function sing() {
console.log("액션 : SING");
}
function dance() {
console.log("액션 : DANCING");
}
mood("good");
상황에 맞게 하나의 함수로 만드는 게 가능해진다.
728x90
반응형