LoginSignup
2
0

More than 5 years have passed since last update.

Light red and blue alternately

Posted at
const timer = require('timers')

const lightList = ['red', 'blue']

const LIGHT = {};
const lights = 'lights';

for (const light of lightList) {
  LIGHT[light] = `${lights} ${light}`
}

const lightAnyColor = ({light, nextLightFunc, lightTime}) => {
  timer.setTimeout(() => {
    console.log(light)
    nextLightFunc();
  }, lightTime);
}

const lightBlue = () => {
  lightAnyColor({
    light: LIGHT.blue,
    nextLightFunc: lightRed,
    lightTime: 1000,
  })
}

const lightRed = () => {
  lightAnyColor({
    light: LIGHT.red,
    nextLightFunc: lightBlue,
    lightTime: 1000,
  })
}
const start = () => {
  lightRed();
}

start();
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0