If I had to guess, it’s because you are printing out a computer choice here:Īs said, you’re not logging the same computer choice that you compare with. Problem : Comments Comment posted by Ibrennan208 Anyway, the code above can still be greatly improved. You can find and operators in several other dynamically-typed languages as well. This operator returns true if the strings are not equal and false otherwise. The above working demo didn’t change much of your code, which i intended to, to keep things clearer and simpler. Use the strict inequality ( ) operator to check if two strings are not equal or not in JavaScript. You may either tell the user to type again until and then the game can kick in. In your code, you didn’t account for the case that the user enters wrong a value (my demo did with a simple return statement). You should either stick to using lowercased values or uppercased ones as, for example, 'ROCK' = 'Rock' // false no matter you use = or = (the last one also checks that the values are of the same type). Sometimes you use uppercased values like ROCK but sometimes you use lowercased/mixed-case values like Paper. The following function first evaluates if the condition (num 55) evaluates to true. The problem, and a flawed approach to solving it Take this ('bad') code, which addresses the classic floating point problem of (0.1 + 0.2) 0.3 returning false: let f1 0.1 + 0.2 let f2 0.3 console.log(Math.abs(f1 - f2) < Number.EPSILON) // 'True - Yippeee' Ok, so far so good. and the last call to "getComputerChoice" is the one that the evaluation function uses. Example of JavaScript Not equal () operator. the value on the first line and the third one are NOT the same console.log(getComputerChoice()) // first lineĬonst playerSelection = prompt("Rock, Paper, SCISSCORS?").toUpperCase()Ĭonst ComputerSelection = getComputerChoice().toUpperCase() // third line With their talents and ambitions, they also have their insecurities, doubts, and worries. The strict equality () operator checks whether its two operands are equal, returning a Boolean result. In such an environment, people feel safe and are not afraid to show their true individuality. The COM choice is executed twice but you only print the first execution result thus you see the wrong final choice on the console. 1.Create an inclusive and productive work environment If youre building a truly equitable workplace, youre also more likely to foster an inclusive work environment. PlayRound = (playerSelection, ComputerSelection) => )() Some side notes (but rather important):Ĭase X: return "." break : the use of break in that case is not necessary as you are returning a value already which means the break statement will never be reached. Return "ROCK" // you are "return"ing a value so no need for using "break" statementĬonst playerSelection = prompt("Rock, Paper, Scissor?").toUpperCase(), Note: (negation operator) as not, (boolean-or operator) as or Example of JavaScript if not equal value value Example of a basic way of using Not equal to the operator in JavaScript, if the condition true then the alert box will pop with an actual vale of value1. Randomnum = Math.floor(Math.random() * 3 + 1) Here is symbol representation of not equal.
0 Comments
Leave a Reply. |