21 Day Coding Challenge

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

#1

2

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

#2

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

And:

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.

#3

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;
}
console.log(somefunc());
Output: returnString

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

#4

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.

#5

HI @ArmandN

DId you end up solving it?

#6

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

Thanks @Seb and @sumitsinghdeode for your help

2 Likes
#7

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

2 Likes
#8

Sure, I can help you out.

#9

Anytime :slight_smile:

#10

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:

2 Likes