I’m not really stuck at the project, as I eventually peeked into the hint section. But I desperatly want to know why my inital code does not work, since in my eyes it only inverts the if / else statement. I really want to understand what is going on, to make sure not to repeat the mistake. In the end, there is no hint in the wild, right.
Link to the complete exercise. My problem is linked to step 3
The insctructions are to create a function and within formulate an if / else statement, to check wheter the user input is valid. If not, an error message should be logged, else the value should be returned and we can go on.
The correct code, which does what it is supposed to do, looks like this:
const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (
userInput === "rock" ||
userInput === "scissors" ||
userInput === "paper"
) {
return userInput;
} else {
console.log("Bitte richtigen Wert eingeben");
}
};
Initally I wrote
const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (
userInput !== "rock" ||
userInput !== "scissors" ||
userInput !== "paper"
) {
console.log("Bitte richtigen Wert eingeben");
} else {
return userInput;
}
};
The solution does return rock, paper or scissor when the input is accordingly, else the error message is logged. My original code always logs the error message no matter the input.
I wrote it anew so many times and I slept over it, still I don’t see where my mistake could be. Why doesn’t it work. The logic still aplies in my mind.
It is highly appreciated it anyone could explain what is going on or forward me to a source of information, since I was not able to find an answer to this issue. Thank you!