/    Sign up×
Community /Pin to ProfileBookmark

How to fix ‘alert’ that affects inner.html display?

A game I’m working on has several rounds of play. After each round an alert shows ‘Correct’ or ‘Incorrect.’ Then a cumulative score is displayed in a separate div using inner.html. All of that works well. So I took out the alert. Now, when the round is over the screen flashes to the next round without displaying the cumulative score. Possibly the cumulative score is displayed momentarily, but that does no good. How do I fix this?
Thanks.

to post a comment
JavaScript

19 Comments(s)

Copy linkTweet thisAlerts:
@justinbarneskinAug 15.2009 — we need some code
Copy linkTweet thisAlerts:
@Vecchio_ZioauthorAug 15.2009 — Relevant code is shown below (out of ~300 lines). The function is in the head; the div is in the body. If you need the whole thing let me know.

function showScore()

{if (success==1 && games<playGames) {msg0=msg1; }

else if (success==-1 && games<playGames) {msg0=msg2; }

//alert(msg0);

var gg="Rounds";

if (games==1) {gg="Round"}

var ww="Wins";

if (wins==1) {ww="Win"}

score = "<center><table border=3 bgcolor=#B4FBAA cellpadding=1 cellspacing=1 height=34 width=536><tbody valign=middle align=center><tr><td><font face='Verdana' size='2'>"+games+" "+gg+" played, "+wins+" "+ww+". You've earned "+poynts+" out of a possible "+mxpoynts+" points.</font></td></tr></tbody></table></center>";

document.getElementById('mynum').innerHTML = score;

}

<div id="myoutput" style="margin:20px 0 0 0">

<div id="mynum" style="display:inline">

</div>

</div>
Copy linkTweet thisAlerts:
@justinbarneskinAug 15.2009 — try using the triple evaluator throughout the code

if(games==1) might evaluate to true

if(games===1) would evaluate to the number
Copy linkTweet thisAlerts:
@Vecchio_ZioauthorAug 15.2009 — I tried the suggestion both in the function only, and then throughout the code. Neither worked...display still flashes to the next round of the game without showing the current score. When I reactivated the alert, then the current score was shown. I watched carefully...the 'flash' seems to go from the correct display to an instantaneous white screen and then to the correct display again. Maybe that's a clue? Any other thoughts?
Copy linkTweet thisAlerts:
@justinbarneskinAug 15.2009 — split your function in two after the alert.

insert a setTimeout("func2()",100) delay to finish the function.
Copy linkTweet thisAlerts:
@JMRKERAug 15.2009 — Are you using a <form> tag?
Copy linkTweet thisAlerts:
@Vecchio_ZioauthorAug 15.2009 — Below is the code after trying several different ways to do as you suggested. My guess is that I don't understand how to incorporate it. Could you mark up the code the right way?

Re. using <form>...there is one use of it in the game portion itself, but not in the div where the score summary is placed.

I'm in over my head...hope you guys can help me out!
-------------------------------


function showScore()

{if (success==1 && games<playGames) {msg0=msg1; }

else if (success==-1 && games<playGames) {msg0=msg2; }

// setTimeout("func2()",1000);

//alert(msg0);

func2();

}

function func2()

{setTimeout("func2()",1000);

var gg="Rounds";

if (games==1) {gg="Round"}

var ww="Wins";

if (wins==1) {ww="Win"}

score = "<center><table border=3 bgcolor=#B4FBAA cellpadding=1 cellspacing=1 height=34 width=536><tbody valign=middle align=center><tr><td><font face='Verdana' size='2'>"+games+" "+gg+" played, "+wins+" "+ww+". You've earned "+poynts+" out of a possible "+mxpoynts+" points.</font></td></tr></tbody></table></center>";

document.getElementById('mynum').innerHTML = score;

}
Copy linkTweet thisAlerts:
@JMRKERAug 15.2009 — Post a link to the game so we can see the interactions of the HTML and JS etc.
Copy linkTweet thisAlerts:
@Vecchio_ZioauthorAug 16.2009 — The game's not yet on internet, so no link. With your permission may I email a zip file to you with the code, js file and other necessary files? Don't want to do that unless you say okay (either of you). Please let me know...and thanks in advance for your great help.
Copy linkTweet thisAlerts:
@justinbarneskinAug 16.2009 — you can upload it like this...

[upl-file uuid=4553a74b-ac89-470b-a548-034fc8cdf746 size=657B]sat5.txt[/upl-file]
Copy linkTweet thisAlerts:
@Vecchio_ZioauthorAug 16.2009 — Here are the files. the alert we've been dealing with is in line 78 of the main code. Thanks.

[upl-file uuid=b283a33f-757b-481d-9e19-086cf83cc1ba size=35kB]VECCHIOZIO.zip[/upl-file]
Copy linkTweet thisAlerts:
@justinbarneskinAug 16.2009 — Ok great. Now give us the answers so we can let the code run through and see whats happening.
Copy linkTweet thisAlerts:
@justinbarneskinAug 16.2009 — I found var rand and set it to 1

I spell the word but you don't show score,

Can you write some convenience to show what is to happen for dummies?
Copy linkTweet thisAlerts:
@Vecchio_ZioauthorAug 16.2009 — The js file contains a 'gw' array with the Greek words, and a 'def' array with the definitions (hints). The code randomly presents a Greek word to be discovered so I can't pinpoint which one to define. You could reduce the length of each array in the js file to, say, 3, so it has a limited number of words to work with. If you do that, also set 'playGames' to 3 (it's on line 48).

The code (and the problem I'm having) works whether or not you get the word right. Just click on any of the letters until you run out of guesses, and it will still display the current score. But it only does that when the alert is used. With the alert turned off by '//' the current score does not display.

Thanks...your quick responses are GREATLY appreciated.
Copy linkTweet thisAlerts:
@justinbarneskinAug 16.2009 — Look, I started adding alerts to see whats going on and, I can't get var games to increment

[code=php]function randomWords()
{success=0;
readCookie(); if(games==playGames) {endGame(); }
else{alert(games+' '+playGames)}
rand = Math.floor(Math.random() * gw.length);
rand=1;
var word = gw[rand].toLowerCase();
gword = word;

return word;
}
[/code]
Copy linkTweet thisAlerts:
@justinbarneskinAug 17.2009 — I work on this quite a bit, I don't know Greek,

change the extension to .html and tell me what you think?

[upl-file uuid=971630bb-15dd-447c-af2d-46abd4850921 size=7kB]greek.txt[/upl-file]
Copy linkTweet thisAlerts:
@Vecchio_ZioauthorAug 17.2009 — Wow! You've greatly simplified the code...8KB vs my 13KB, and even so you put the js file into the code body. Impressive to say the least. And, you solved my problem...score appears even without the 'confirm' you added. Only problem there is that I'm not sure how to incorporate it into my version (which I'd like to do for learning purposes). Two things: when you click a Greek letter it should appear in each position in the word where it belongs. In the code you sent it appears only in the first location, so the word cannot be completed. And, I couldn't figure out from the code you sent how to move on to the next word without using the confirm. (The game should have neither an alert nor a confirm in order to minimize clicks for the user).

var games does index up in the version I sent, but it does so via writing and reading a cookie.

Thanks a million...you're obviously highly skilled in javascript. Any additional comments you might have vis a vis what's written above will be more than welcome.
Copy linkTweet thisAlerts:
@justinbarneskinAug 17.2009 — You would have been more lucky if the likes of Kor would have helped you.

Yes, the script is still very buggy-

Will remove the return statement in callMe() function. A true/false var must be used there instead.

Problems with var rand if rand is zero

Won't have time to work on it more until later today.
Copy linkTweet thisAlerts:
@justinbarneskinAug 17.2009 — Ok, I'm about wore out on this, don't think I want to work on it anymore

You'll have to solve your variables mxpoynts and ratios

[upl-file uuid=a9e0d5c7-c220-4c87-8bef-6a88768d6d6e size=7kB]agreek.txt[/upl-file]
×

Success!

Help @Vecchio_Zio spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...