Montross: Javascript518 also you can use the break; statement to exit loops when you want to, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break for more info
Merkling: Still having an issue with this. Was able to fix the parameters in the While loop, but now it’s not functioning as intended. Instead of looping until the user inputs a matching string, it just closes and seems to lag the hell out of chrome https://gist.github.com/anonymous/0e2c898cd4ddf8bfbe37
Creach: Noob321: I would avoid using while loops like this, too easy to cause infinite loops
Rathgeb: And you should automate your code a bit and split things into functions
Phlieger: It becomes difficult to reason about it with all the if/else if/else conditions
Degenhart: E.g. if “rock”,”paper”,”scissors”.indexOfuserChoice = 0 { do stuff }
Wozney: Putting your choices in a structure such as an array makes it easy to do things
Bolerjack: Monomon, even better, at least for this rock paper scissors is to use an object
Ruel: What would be a better way to get to the same end goal of that While function? And sorry, I know it’s pretty sloppy code but this is the first time I’ve ever coded anything.
Bea: Noob321: ok no problem, I can walk you through this
Ankersen: Bolerjack: not sure what your idea is, but I guess it can work
Bolerjack: To encode the results in an object
Samide: I was talking earlier about the possible choices
Burrell: Can you change a global variable in a While function? Or am I missing something else?
Bolerjack: The obejct contains the possible choices *AND* the results
Apel: Bolerjack: there’s many ways to turn this pancake :
Thoby: Noob321: sure you can, but that is not your problem
Saka: You are causing an infinite loop somewhere, which repeatedly calls the same thing
Salfelder: That’s why the browser gets stuck
Bolerjack: Osbon, Noob321, this is what I meant basically http://jsfiddle.net/t2s4h42g/
Bolerjack: Then you can randomize Object.keysgames for a computer
Stgermain: I haven’t gotten into objects yet. I can’t seem to find what is causing this infinite loop. I know it’s the While function on line 2, but not sure where the problem is within it.
Bolerjack: That’s for the computer http://jsfiddle.net/t2s4h42g/1/
Fanny: Noob321: give me a couple moments to write it up
Capparelli: Noob321: imagine userChoice is set to “scissors”; then what is the value of userChoice !== “scissors” ?
Mayotte: UserChoice !== “scissors”
Geraldes: It’d be true, and the While function wouldn’t run, right?
Nedman: That’s not the whole condition
Beers: Var userChoice = “scissors”; userChoice !== “scissors”
Wakley: Deltab: boolean false
Scurci: Var userChoice = “scissors”; userChoice !== “paper”
Rodenizer: Var userChoice = “scissors”; userChoice !== “rock”
Hartle: The condition is true, so the loop continues
Falkenhagen: Deltab is right, you need to && the conditions in this case
Querry: Noob321: let’s start with the basics https://jsbin.com/latezonovi/edit?js,console,output
Boschee: Doesn’t work as OR? I figured it would check if userChoice !== “paper”, then “scissors” and if none were true the While function ran.
Vlahos: Noob321: no, for negative conditions you need to && them
Edgerly: Because it will always be different from at least two of them
Wienert: But anyway, should we organize your code a bit?
Shantz: Https://jsbin.com/latezonovi/edit?js,console,output
Oldfather: We stat by extracting our operations into functions
Youngquist: So you have getRandomChoice and isValidEntry
Em: These both work with the collection of possible choices that you create