Guys hi, ı need help

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, update_light(‘green’) should return ‘yellow’.

Hi everyone. How can ı do this.?

You could use a switch statement or ifelse statements, eg:

const update_light = current_status => {
  switch (current_status) {
    case 'green':
      return 'yellow'
      break
    // insert other statements here
  }
}

console.log(update_light('green'))
# prints yellow
const update_light = current_status => {
  if (current_status == 'green') {
    return 'yellow'
  } else if (current_status == 'yellow') {
    // continue rest of the code
  }
}

console.log(update_light('green'))
# prints yellow

its upt o you which you’d like to use, but either of these work! I’ve not completed either so you can work on the rest of it yourself.

1 Like

Thanks a lot ^^ ı will work