DESCRIPTION:
You're writing code to control your town's traffic lights. You need a function to handle each change from green, to yellow, to red, and then to green again.
Complete the function that takes a string as an argument representing the current state of the light and returns a string representing the state the light should change to.
For example, when the input is green, output should be yellow.
설명:
당신의 도시의 신호등을 제어하기 위한 코드를 작성합니다. green에서 yellow, red, 그리고 다시 green으로의 전환을 처리할 수 있는 함수가 필요합니다.
빛의 현재 상태를 나타내는 문자열을 인수로 받아서 바뀌어야 하는 빛의 상태를 문자열로 반환하는 함수를 완성하세요.
예를 들어, green이 입력되면 yellow를 출력해야 합니다.
function updateLight(current) {
if(current === 'green'){
return 'yellow';
} else if (current === 'yellow'){
return 'red';
} else {
return 'green';
}
}
https://www.codewars.com/kata/58649884a1659ed6cb000072/javascript
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Binary Addition (7 kyu) / JavaScript (0) | 2022.09.29 |
---|---|
[Codewars] Descending Order (7 kyu) / JavaScript (0) | 2022.09.28 |
[Codewars] Multiples of 3 or 5 (6 kyu) / JavaScript (0) | 2022.09.27 |
[Codewars] Credit Card Mask (7 kyu) / JavaScript (0) | 2022.09.26 |
[Codewars] List Filtering (7 kyu) / JavaScript (0) | 2022.09.26 |
댓글