Welcome to WebmasterWorld Guest from 54.167.86.211

Forum Moderators: open

Message Too Old, No Replies

JavaScript is a pain

Mostly cause I'm not used to coding in it. HELP!

     
8:34 pm on Feb 1, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:May 3, 2001
posts:365
votes: 0


Hi all,
Small problem here.
I want to have the variable i add one for every if statement it goes through.
But it keeps giving me 1 and I just don't know what I'm doing wrong.

Can anybody help?

<script language="JavaScript">
var i = 0;
if ("200107100000" && "200107150000") {
i = +1;

document.write ("<tr>");
document.write ("<td align=\"center\">");
document.write (i);
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200107100000");
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200107150000");
document.write ("</td>");
document.write ("</tr>");

}
if ("200108170000" && "200108140000") {
i = +1;

document.write ("<tr>");
document.write ("<td align=\"center\">");
document.write (i);
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200108170000");
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200108140000");
document.write ("</td>");
document.write ("</tr>");

}
if ("200109050000" && "200109070000") {
i = +1;

document.write ("<tr>");
document.write ("<td align=\"center\">");
document.write (i);
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200109050000");
document.write ("</td>");
document.write ("<td align=\"center\">");
document.write ("200109070000");
document.write ("</td>");
document.write ("</tr>");

}
</script>

12:07 am on Feb 2, 2002 (gmt 0)

Full Member

10+ Year Member

joined:May 14, 2001
posts:262
votes: 0


you need to change the line "i = +1" to read either:
i = i + 1
or
i += 1 (I think this works in Javascript).

Your line of code is simply assigning "positive 1" to the i variable during each iteration.

11:13 pm on Feb 3, 2002 (gmt 0)

Full Member from GB 

10+ Year Member

joined:Oct 16, 2001
posts:201
votes: 0


i=++1
should also work.
1:38 am on Feb 4, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2001
posts:1259
votes: 11


as well i++ :-)
6:56 pm on Feb 4, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:May 3, 2001
posts:365
votes: 0


Hi all,

Got that part to work by using
i = i+1;

Thanks to all, it worked. :)

justa, I tried it like so
i = ++1;

Cause thats how I do it in PHP which is what I'm mostly used to. But no cigar in JS. But thanks for the help anyways.

:)

Thank you all

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members