/    Sign up×
Community /Pin to ProfileBookmark

Help: Display numbers 1 to 30.

Hi evrybody, i am new to JavaScript, I am trying to disply from 1 to 30 skipping the ones from 17 to 23 (included).
I came up with the following code:

<script type=”text/javascript”>
var number = 1

for (index=0;index<30;index++){
if (((number+=index)>16) && ((number+=index)<=23)){
document.write((index+1)+ “. Skipping”);
document.write(“<BR>”);
}else{
document.write((index+1)+”. “+(number+=index));
document.write(“<BR>”);
}
}
</script>

Thank u in advance

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERApr 23.2010 — Put your code between [ code] and [ /code] tags (without the spaces) to make it easier to read.

Then try this...
<i>
</i>&lt;script type="text/javascript"&gt;

for (index=1;index&lt;=30;index++){
if ((index&gt;=17) &amp;&amp; (index&lt;=23)){
document.write((index)+ ". Skipping");
}else{
document.write((index+". ");
}
document.write("&lt;BR&gt;");
}
&lt;/script&gt;

(number+=index) in the if statement is your cuplrit as it changes the 'number' value frequently
Copy linkTweet thisAlerts:
@Slow_poison88authorApr 23.2010 — Ok, thank man, it worked.. Next time i will make it much easier to read. Now i must make the user prompt for a valid number (number>0) and show all 10 odd numbers following it. for example if the user enters 9, you show 11-13-15 . . . 25-27-29. can you help
Copy linkTweet thisAlerts:
@NicTltApr 23.2010 — <i>
</i>&lt;script&gt;
for (var index = 1; index &lt;= 30; index++) {
document.write(index + '. ' + (((index &lt; 17)||(index &gt; 23)) ? '' : 'Skipping') + '&lt;BR&gt;');
}
&lt;/script&gt;

or, if you don't want to write out the skipped numbers:
<i>
</i>&lt;script&gt;
for (var index = 1; index &lt;= 30; index+= (index === 16) ? 8 : 1) {
document.write(index + '. &lt;BR&gt;');
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@Slow_poison88authorApr 23.2010 — thank you very much, now can you please help me with the second one...
Copy linkTweet thisAlerts:
@Slow_poison88authorApr 23.2010 — This is what i have
function ValidateInput(formInput){
if(IsEmpty(formInput.textInput))
{
alert('You have not entered an account number')
formInput.textInput.focus();
return false;
}

<i> </i> if (!IsNumeric(form.textInput.value))
<i> </i> {
<i> </i> alert('Please enter only numbers or decimal points in the account field')
<i> </i> form.textInput.focus();
<i> </i> return false;
<i> </i> }
return true;


My form looks like this
&lt;FORM name="formInput" action=#self onsubmit="javascript:return ValidateInput(formInput)"&gt;
Input Text: &lt;input type="text" name="inputText" /&gt; &lt;BR&gt;&lt;BR&gt;
&lt;input type="submit" value="Submit" /&gt;
&lt;/FORM&gt;
×

Success!

Help @Slow_poison88 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.18,
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,
)...