Gamaliel
Gamaliel

Reputation: 77

Can't understand instructions in Javascript

So, I have a task assigned to me but I find that the instructions is a little deep and english isn't my native language. So here's the instructions:

And here's how I've seen it:

var move = getInput();
if (move === getInput) {
    console.log("Player: " + move);
}
else if (move === null) {
    getInput():
};
return getInput (move);

Upvotes: 2

Views: 96

Answers (1)

t3dodson
t3dodson

Reputation: 4007

Truthy and Falsy values

getInput is a function. When you get to

if (move === getInput) // rest of code

This is checking to see if the result of calling getInput() is the reference to the function itself ... this is probably not what you want.

If checks for Truthy values.

null is not truthy so a sufficient test for your input would be

if (move) // rest of code.

move will be populated with getting the input. so thats why it will make sense to console.log it in the body of the if statement.


Further more

you don't need to explicity check using else if because you are checking a direct negation of your if.

so instead your format should be

if (move) {
// ...
} else { // no need for else if here. null is implied.
// ...
}

Upvotes: 3

Related Questions