21 Day Coding Challenge

#13 - Can someone explain why this code is wrong?



I’ve got no clue… All help is appreciated!


a return statement will stop the execution of your function, so in this case, your

navigation.x = signal;

is executed at every iteration of your loop


if (signal !== undefined) {

Will suddenly stop the function, due to the return statement. The function will return the value of the variable signal, but in this case, we’re not that interested in it.


Pretty nice explanation @Seb. Just to add on for return statements:
In this case you are returning value for ‘signal’ which here is equals to checkSignal() when it is not defined. This returning statement refers the value of function to be same as returned value of ‘signal’.

Think of this with an example:

function somefunc(){
//some calculation or processing
return returnString;
Output: returnString

This may not be that helpful but could give you an idea what return statement actually does. :smile:


When you are using
return signal
It came out of the coding block, in order to use the signal variable used it in the if block and return after assigning it.


HI @ArmandN

DId you end up solving it?


Hi! Thanks for checking in. Yes I did end up solving it by changing my code around.

Thanks @Seb and @sumitsinghdeode for your help


@Seb Leave some people to help to me jeez :heart: :joy:


Sure, I can help you out.


Anytime :slight_smile:


I took yesterday off, that should be plenty!!! :wink: You’d be surprised to hear that I usually don’t even read my emails. :stuck_out_tongue: