Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Level 4 > lesson 4

let signal = "green";
if(signal=="yellow"){
console.log("Wait");
}
else if ( signal == "yellow" && !"green"){
}
else if (signal =="yellow" && !"red"){
console.log("Wait");
}
else if (signal =="green"){
console.log("Go");
}
else if (signal == "green" && !"yellow"){
console.log("Go");
}
else if ( signal == "green" && !"red"){
console.log("GO");
}
else if ( signal=="red"){
console.log("Stop");
}
else if (signal == "red" && !"yellow"){
console.log("Stop");
}
else if (signal == "red" && !"green"){
console.log("Stop");
}
else{
console.log("Error");
}
Hello!
how did you guys make this code execute and proceed to the next level. Is there a much more simple way to write this code and please correct me where I am getting it wrong.
Thank you!
by

1 Answer

sam5epi0l
Try this code:


let signal = "yellow";
// write logic here
if(signal == 'green'){
console.log('Go');
} else if(signal == 'yellow'){
console.log('Wait');
} else if(signal == 'red'){
console.log('Stop');
} else{
console.log('Error');
}

Login / Signup to Answer the Question.