if (btnType === "pick") {
// Set newState.match to either true or false depending on whether or not the dog likes us (1/5 chance)
newState.match = 1 === Math.floor(Math.random() * 5) + 1;
// Set newState.matchCount equal to its current value or its current value + 1 depending on whether the dog likes us
newState.matchCount = newState.match
? newState.matchCount + 1
: newState.matchCount;
} else {
// If we thumbs down'ed the dog, we haven't matched with it
newState.match = false;
}
// Replace our component's state with newState, load the next dog image
this.setState(newState);
this.loadNextDog();
};
I would think that the expression in the ternary operator would overwrite the value in newState.match. However, when the value actually gets executed newState.match continues to be a number. Why is that ? Also, I get an error when i replace the expression in the ternary operator with
newState.match
? newState.matchCount + 1
: newState.matchCount;
}
Why? shouldn’t it do the same thing?