Function couldn't be equal in if condition?

why result showed ‘diff’ while user input and pc input is equal?
thanks.

because you call the function twice, once to display what the user picked:

console.log(`user input is <${user()}>`);

and for the comparison:

if(user()===pc()){console.log('same')}

but each time you call the function, a new random choice is generated.

1 Like

got it, thanks.

it works well if declare varaible=function(), in this case function would not be called twice.

const a1=user();
const b1=pc();
console.log(a1);
console.log(b1);
if(a1===b1)
{
console.log(‘same’)
}
else
{
console.log(‘diff’)
};

exactly, nicely done :slight_smile:

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.