/    Sign up×
Community /Pin to ProfileBookmark

Problem with for loop

This is frustrating me. The loop runs once and doesnt even get to the bottom of it… there arent any errors either!… Help plz

Declaring the arrays:

[code]
var fake_start = new Array()
var fake_end = new Array()
var realstart = new Array()
var realhours = new Array()
var realend = new Array()
var jobtype = new Array()
var tod_e = new Array()
var tod_s = new Array()
[/code]

Declaring the 2 dimensional array:

[code]
var cell = new Array(9);
for(i=0;i<cell.length;i++)
cell[i] = new Array(20);
[/code]

Setting up test values to the arrays:

[code]
jobtype[0]=”test”
for(a=1;a<7;a++)
{
realstart[a] = “7:30”
realend[a] = “14:00”
jobtype[a] = “T”
}
[/code]

The loop that is makin me frustrated.
It runs if the times for realstart are without minutes like 7:00 or 8:00, but once i make it 7:30 or 8:10 ect it messes up some how…

[code]
for(a=0;a<4;a++)
{
if(realstart[a] == “” || realend[a] == “” && 0)
{
fake_start[a] = “”
fake_end[a] = “”
realhours[a] = “0”
tod_s[a]=”AM”
tod_e[a]=”AM”
}
else
{
startdate.setTime(Date.parse(‘October, 4 2000 ‘+realstart[a]+’:00′));
enddate.setTime(Date.parse(‘October, 4 2000 ‘+realend[a]+’:00′));
if(startdate.getHours() > 12 || (startdate.getHours() == 12 && startdate.getMinutes() > 0))
{
tod_s[a] = “PM”
startH=startdate.getHours()%12
}
else
{
tod_s[a] = “AM”
startH=startdate.getHours()
}

if(startdate.getMinutes()<10)
{
startM=”0″+startdate.getMinutes()
}
else
{
startM=startDate.getMinutes()
}
if(startH==0)
{
startH=12
}

if(enddate.getHours() > 12 || (enddate.getHours() == 12 && enddate.getMinutes() > 0))
{
tod_e[a] = “PM”
endH=enddate.getHours()%12
}
else
{
tod_e[a] = “AM”
endH=enddate.getHours()
}
if(enddate.getMinutes()<10)
{endM=”0″+enddate.getMinutes()}
else
{endM=enddate.getMinutes()}
if(endH==0)
{endH=12}

fake_end[a] = endH+”:”+endM;
fake_start[a] = startH+”:”+startM;
worked = (enddate-startdate)/(60*60000)
if(worked<0){worked*=-1;}
worked = Math.round(worked*100)/100
realhours[a] = worked
}
}
[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@ralbrittonJan 14.2005 — If you use alerts on every line, you can tell exactly where it breaks.

Are you sure it doesn't throw an error? I've found that many times my code just doesn't work and I don't have my error notification turned on.

<Deleted text re: arrays because I had skipped right to the code and didn't see the top part.>
Copy linkTweet thisAlerts:
@ScriptNoobie86authorJan 14.2005 — it stops at the line:
<i>
</i> if(startdate.getMinutes() &lt; 10)
{
startM = "0"+ startdate.getMinutes()
}
else
{
startM = startDate.getMinutes() &lt;&lt;--Stops Here... Dont know why...
}

it doesnt make sense to me... Theres no error, i always have my notification turned on and i know it is on bc i get other errors when im coding i have to fix.

Also, it works if its under 10, but if its over 10 it stops w/o any error msg...
Copy linkTweet thisAlerts:
@ScriptNoobie86authorJan 14.2005 — well i fixed it, but i still dont know whats wrong with it.

I would like to know why the code worked:
<i>
</i>if(startdate.getMinutes() &lt; 10)
{
startM = "0"+ startdate.getMinutes()
}
else
{
startM = startDate.getMinutes() &lt;&lt;--Stops Here... Dont know why...
}


but this didnt:
<i>
</i> if(startdate.getMinutes()&lt;10)
{
startM="0"+startdate.getMinutes()
}
else
{
startM=startdate.getMinutes()
}


Edit:

omg i capitalized startDate...

its startdate not startDate...

thread closed
Copy linkTweet thisAlerts:
@ralbrittonJan 14.2005 — Yep. That'll getcha every time. Glad you found it.

(You're not such a newbie if you can catch your own mistakes!)
Copy linkTweet thisAlerts:
@irasterbJan 14.2005 — Did you notice that you mixed a capital d (D) and small d (d). YOu have to be consistant.

Ira
Copy linkTweet thisAlerts:
@ScriptNoobie86authorJan 14.2005 — yeah i did notice afterwards. its just habit. java convention is capitalize the 1st letter of every word after the 1st guess i got lazy lmfao
×

Success!

Help @ScriptNoobie86 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 5.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...