Closed ghost closed 9 years ago
Hey Alea, not sure I understand the issue 100%. Could you provide some more context?
That being said, are you getting any errors in the console? As this code example stands, you can't call changeScore( )
in its current position because it only exists inside the scope of takeScore( )
.
What i'm trying to achieve is that when you click the score button it will start taking score of the game. But only when you click that button otherwise the score should not be taken. I've just been moving the changeScore() function around in hopes that maybe that would solve the issue.
Hah, well, that's one way to do it. Where do you have var score
?
Better yet, could you push your code to Github so I can take a look at your whole code?
var score = 0 is in the global floating around waiting to be used
I think you need to fix your indentation. It looks like changeScore
is inside takeScore
. Therefore, takeScore
isn't available outside of changeScore
. This will be easier to see if your indentation was consistent!
changeScore is inside takeScore....erm...maybe thats the issue?
See previous comment! :)
but i'm calling takescore so wouldn't that in turn call changesscore? I had changescore() commented out before while i was testing. I still have the issue of the score not changing which is why I started putting changescore() all over the place
Still fix the indentation!
I don't know what I would fix it to it's indenting in a way that makes sense to me
Here's an example:
function takeScore() {
$("#button2").click(function(){
$(".numberbox").html("score:"+ ' '+score )
})
function changeScore(){
if (card1==card2){
score++;
$(".numberbox").html("score:"+ ' '+score )
}
if(card1 !== card2){
score--;
$(".numberbox").html("score:"+ ' '+score )
}
/* let them know they kinda suck*/
if (score == -3){
alert("Seriously tho? try a little harder :-(")
}
}
To...
function takeScore() {
$("#button2").click(function(){
$(".numberbox").html("score:"+ ' '+score )
})
function changeScore(){
if (card1==card2){
score++;
$(".numberbox").html("score:"+ ' '+score )
}
if(card1 !== card2){
score--;
$(".numberbox").html("score:"+ ' '+score )
}
/* let them know they kinda suck*/
if (score == -3){
alert("Seriously tho? try a little harder :-(")
// this } was missing
}
}
}
This showed me that there was a missing curly bracket.
Atom makes it easy! You can select multiple lines and hit Tab
to indent them to the right, and Shift
-Tab
to un-indent them to the left.
The way you submitted it initially in this issue was great! It looks like it just got mungled a bit when it went up to Github.
I'm trying to active the score button on click and only count the score if that button was clicked. If the button was not clicked the score would not be kept. I've had the score outside of the click and then it shows up whether you push the button or not and starts taking score. So then I put it in the click but then it only updates the score when you keep clicking the button. I'm not sure how to have it only active when the score button is kept and stay de-active when its not clicked.