How to build a Traffic Light simulator (React Js Interview question)

Поделиться
HTML-код
  • Опубликовано: 1 дек 2024

Комментарии • 14

  • @anandbaraik5010
    @anandbaraik5010 Год назад

    You are doing great work ❤ thanks for bringing this machine coding questions!

    • @xplodivity
      @xplodivity  Год назад

      Thanks a lot, appreciate it!!

  • @RavindraSingh-zg9eq
    @RavindraSingh-zg9eq 7 месяцев назад

    really helpful and nice way to do this
    .import React, { useState, useEffect } from 'react';
    import './style.css';
    export default function App() {
    const [currLight, setCurrLight] = useState('green');
    const trafficState = {
    red: {
    duration: 4000,
    backgroundColor: 'red',
    next: 'yellow',
    },
    yellow: {
    duration: 500,
    backgroundColor: 'yellow',
    next: 'green',
    },
    green: {
    duration: 3000,
    backgroundColor: 'green',
    next: 'red',
    },
    };
    useEffect(()=>{
    let timer=setTimeout(()=>setCurrLight(trafficState[currLight].next),trafficState[currLight].duration)
    return ()=>clearTimeout(timer)
    },[currLight])
    return (

    {Object.keys(trafficState).map((color,ind) => (

    ))}

    );
    }
    //style.css
    .container {
    border: 1px solid black;
    width: 130px;
    }
    .box {
    height: 100px;
    width: 100px;
    border: 1px solid black;
    border-radius: 50%;
    margin: 10px;
    background-color: gray;
    }

  • @aakashsrivastava5557
    @aakashsrivastava5557 6 месяцев назад

    Awesome content man...

  • @ItsRavinderSinghh
    @ItsRavinderSinghh 8 месяцев назад

    Great Video

  • @investneur8232
    @investneur8232 10 месяцев назад

    awesome

  • @jayakumar9976
    @jayakumar9976 Год назад

    Nice. PLease make this kind of similar video. But you increase the length of the videos little bit.

    • @xplodivity
      @xplodivity  Год назад

      Thanks, and sure I will do that!!

  • @HARDY4006
    @HARDY4006 Год назад

    Same question was asked to me in a Bangalore based start up

    • @xplodivity
      @xplodivity  Год назад +3

      Yes this question is getting some “traffic” these days 😅 hope you were able to build it!!

  • @ashortone
    @ashortone 5 месяцев назад

    Now make a netherlands trafficlight

  • @HARDY4006
    @HARDY4006 Год назад

    Do you work in a startup?? Or are you a freelancer or you might be in tech giants like Microsoft, Google , Amazon , atlassian ??

    • @xplodivity
      @xplodivity  Год назад +4

      All I can say is, I am just an engineer who strives to learn something every single day. 😁