Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

NO "ELSE" STATEMENT IN THIS CODE

this.go = function (currentState) {
    if (currentState == LightState.GREEN) {
      console.log("Green --> for 1 minute")
      this.change(LightState.YELLOW)
      return
      
    }
    if (currentState == LightState.YELLOW) {
      console.log("Yellow --> for 10 seconds")
      this.change(LightState.RED)
      return
    }
    if (currentState == LightState.RED) {
      console.log("Red --> for 1 minute");
      this.change(LightState.GREEN)
      return
    }
    if (currentState != LightState.GREEN && currentState != LightState.RED && currentState != LightState.YELLOW) {
      throw Error("Invalid State")
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: constructor function javascript and creating an object from it 
Javascript :: como saber si un afecha es mayor o menor js 
Javascript :: how to move an array over one 
Javascript :: setting a date range using yup on react date picker 
Javascript :: JavaScript : Generate random element of an array : 
Javascript :: misturar dois arrays javascript 
Javascript :: fb like image window js 
Javascript :: JavaScript endsWith() example with length parameter 
Javascript :: jquery select convert into input text 
Javascript :: myModal 
Javascript :: Dublin, Edinburgh, Lisbon, London getcurrentdatetime in angularjs 
Javascript :: data error in jquery validate add custom element 
Javascript :: localStorage check 
Javascript :: eleventy stringify 
Javascript :: how to send multiple values in event in javascript 
Javascript :: i wanted to detect when a user enters an alphabet key in input text javascript 
Javascript :: radio button in react native expo 
Javascript :: tour-app-api 
Javascript :: jq query online tutorial 
Javascript :: checkout code 
Javascript :: jquery get selected checkbox items and pass to parameter for C# MVC consumption 
Javascript :: how can i use two api at the same time in angular 
Javascript :: waitfordisplayed 
Javascript :: import all var js 
Javascript :: create immutable array in javascript 
Javascript :: paramters and arguments 
Javascript :: how to escape double quotes in json 
Javascript :: Your task is to take every letter and its index and form a string out of them. javascript 
Javascript :: microseconds to current time js code 
Javascript :: accessing parents DOM 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =