ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

Simon Game #267

Closed khoitle closed 8 years ago

khoitle commented 8 years ago

Hey, I'm trying to figure out how to store a button value, and if it equals the sequence index, it'll continue the game. If not, then it'll just prompt "Try again."

Here is my code.

function newRound() {
  var sequence = [1, 2, 1]
  animate(sequence);
  var userClick = $("button").val();
  $("button").click(function(){
     var userClick = $("button").val();
     var userClickInput = userClick.value
     console.log(userClickInput);
  })
  if (userClickInput === sequence){
     alert("Yay")
   }
   else {
     alert("Try Again!")
   }
}
nolds9 commented 8 years ago

One thing that might be helpful is to have the eventListener, outside the function. Or to pass a reference to your function, as the second argument to the event listener...

i.e:

function newRound() {

}

$("button").on("click", newRound)
nolds9 commented 8 years ago

also, I don't think a button can have a value, maybe you want to grab the input's value...

khoitle commented 8 years ago

I'm not sure how to do that.

I got the JS to work, but when i click the button it goes straight to the else statement. I think i need to change the IF condition

Here's my html

khoitle commented 8 years ago
nolds9 commented 8 years ago

hey @KhoiLe89 looks like the html did not come through.... mind posting again

khoitle commented 8 years ago

html posted on slack. its not showing up in here for some reason.

jshawl commented 8 years ago

@KhoiLe89 how are you doing on this issue? any progress?

nolds9 commented 8 years ago

going to go ahead and close this since we talked yesterday about this, feel free to reopen if issue persists