본문 바로가기
알고리즘/Codewars

[Codewars] Thinkful - Logic Drills: Traffic light (8 kyu) / JavaScript

by fluss 2022. 9. 25.

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

댓글