By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,462 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,462 IT Pros & Developers. It's quick & easy.

If...Else and variables and counts

P: n/a
I am trying to incorporate a count into a variable within an if...else
statement. Here is the code. I cant get it to work. perhaps someone
can assist me.

folder = window.prompt('starting folder','default');
picnumber = window.prompt('pictures taken?','default');
f2 = parseFloat(folder);
p2 = parseFloat(picnumber);
varAdd = f2+p2-1;
varImg = p2;
var9 = '000';
var99 = '00';
var999 = '0';
var9999 = '0000';

for (count1=f2;count1<=varAdd;count1++)
if (count1 <=9)
varFc = var9999 + count1 +;
else if (count1 <=99)
varFc = var9 + count1 +;
else if (count1 <=999)
varFc = var99 + count1 +;
else if (count1 <=9999)
varFc = var999 + count1 +;
else
varFc = + count +;
document.write('mkdir',varFc,'<br>');
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Tank <is*******@yahoo.com> wrote in message
news:99**************************@posting.google.c om...
I am trying to incorporate a count into a variable within an if...else
statement. Here is the code. I cant get it to work. perhaps someone
can assist me.

folder = window.prompt('starting folder','default');
picnumber = window.prompt('pictures taken?','default');
f2 = parseFloat(folder);
p2 = parseFloat(picnumber);
varAdd = f2+p2-1;
varImg = p2;
var9 = '000';
var99 = '00';
var999 = '0';
var9999 = '0000';

for (count1=f2;count1<=varAdd;count1++)
if (count1 <=9)
varFc = var9999 + count1 +;
else if (count1 <=99)
varFc = var9 + count1 +;
else if (count1 <=999)
varFc = var99 + count1 +;
else if (count1 <=9999)
varFc = var999 + count1 +;
else
varFc = + count +;
document.write('mkdir',varFc,'<br>');


Hi,
not best, but most similar to what you've got...

var folder = window.prompt('starting folder','default');
var picnumber = window.prompt('pictures taken?','default');
// SHOULD check the input for correctness, though

var f2 = parseFloat(folder);
var p2 = parseFloat(picnumber);

var varAdd = f2+p2-1;
var varImg = p2;
var var9 = '000';
var var99 = '00';
var var999 = '0';
var var9999 = '0000';
var varFc;

// for test purposes, display the init values before getting into the loop
document.write( 'start=' + f2 + '<br>');
document.write( 'pic=' + p2 + '<br>');
for (var count1=f2; count1<=varAdd; count1++)
{
if (count1 <=9)
varFc = var9999 + count1;
else if (count1 <=99)
varFc = var9 + count1;
else if (count1 <=999)
varFc = var99 + count1;
else if (count1 <=9999)
varFc = var999 + count1;
else
varFc = count1;
document.write('mkdir' + varFc + '<br>');
}
Jul 20 '05 #2

P: n/a
JRS: In article <99**************************@posting.google.com >, seen
in news:comp.lang.javascript, Tank <is*******@yahoo.com> posted at Tue,
10 Feb 2004 17:05:22 :-
I am trying to incorporate a count into a variable within an if...else
statement. Here is the code. I cant get it to work. perhaps someone
can assist me.


You appear to be trying to count with leading zeroes.

To do that most readily, increase the count by, say, one billion; and
after converting to a string use substring() to remove unwanted leading
digits. If the count K is 7,

document.write('mkdir', String(1e12+K).substr(9), '<br>')

will write mkdir0007 .

But evidently you need to study javascript syntax, as well as
algorithms.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.