Forums
May 04, 2024, 06:59 AM

Author Topic: need some help with javascript code  (Read 365 times)

0 Members and 1 Guest are viewing this topic.

Offline HHC

need some help with javascript code
« on: November 12, 2013, 01:34 AM »
please  :)

I wrote a lil piece of code that simulates footie matches. Check the attachment.
It's not the full code I included, but just the part that matters. The actual code starts with the definition of variables firstteam, firstrank (an index to determine team strength) & points1 (for number of points in a season). There's variables like this for 6 teams in total.

The 2nd part of the code, at the top of the screenshot, is the part that simulates a single match with the use of a function. It first determines # of goals scored, and then for each goal compares the rating of both squads (+a random number to enable the weaker team to score despite having a lower skill index). It then loops till all goals have been 'divided' over the teams and a final score is published.

The third part of the code is a long list of matchups (a full competition schedule of 6 teams). This is the part that fails on me :(
For some reason the script stops right after the 3rd matchup. (as indicated with a red line in the screenshot). And I can't for the love of God figure out how I can make the script proceed after this :(
I presume it has to do with variables being re-defined. As the 4th matchup is where the 2nd matchday start and each team plays its 2nd match. But what the problem exactly is, I dunno.
I guessed it might be the points part, as thats the only variable that gets a new value every time I call the function, but when I changed that of the 4th match to points7 & points8, it still wouldn't go beyond the 3rd.  ???

The box in the bottom right of the screenshot is what I see when I open the HTML page.

+1: Would be nice as well, if someone could tell me how to break lines, so it's not all clustered together.  :-[ I found on the internet a solution by going out of java and into html just to use <br>, but yeah... seems like a real bother if you gotta repeat that over a dozen times.

+2: the document.write thing at the very bottom also gives me a problem. Shows undefined instead of the value I want it to show. (it doesnt show in the code now, as like i said, it stops after the 3rd matchup line, but if i put it up I get this error).


NOTE: I've started getting into html & java just one and a half week ago. I'm naab, so make it easy  ;)

Re: need some help with javascript code
« Reply #1 on: November 12, 2013, 07:54 AM »
1. Don't post your code as a screen shot. There is special tag for it :)
2. It stops because probably some error occurs. Chrome & Firefox have good built-in web dev tools, you can check there.
3. You are not familiar with arrays yet? They will make your life easier :D
4. To break lines in html use <br />. To break lines in "source" code and alerts use "\n".
5. Don't call javascript "java" ;D


dt`wreckz: zooks are effected my win

Offline Husk

Re: need some help with javascript code
« Reply #2 on: November 12, 2013, 02:15 PM »
1. collect underpants
2. ??
3. profit!!!

Offline HHC

Re: need some help with javascript code
« Reply #3 on: November 12, 2013, 04:42 PM »
1. Don't post your code as a screen shot. There is special tag for it :)
2. It stops because probably some error occurs. Chrome & Firefox have good built-in web dev tools, you can check there.
3. You are not familiar with arrays yet? They will make your life easier :D
4. To break lines in html use <br />. To break lines in "source" code and alerts use "\n".
5. Don't call javascript "java" ;D

1.oh
2.K, will check it :)
3.I know vaguely what arrays are, and even made some in a quick tutorial.. but yeah, need to get into them more. I guess you're right though, it would make the code a lot smaller, thus better.
4.Think I tried the n-thing, didnt work then. I'll have to check again.
5.Oh sorry! xD

Ty statik. Hope I can figure out whats bugging tonight.