Hello i want to do a count from 1 to 30 (1,2,3,4,5,6,7,8,9 etc) with javascript I did this

var i = 1;
    if(i<=30)
    {
        i++;
    }

    '<span>#'+i+'</span>'

all good but the count starts from 0 not 1 as wanted

Recommended Answers

All 4 Replies

Member Avatar for diafol
for( i = 1; i <= 30; i++ ){
    ...
}

Or am I missing something?

The code you presented does not count 1,2,3,4,5 ... not from 0 or 1 or otherwise. As diafol pointed out, you need a loop.

OK. I knew from the beggining that it would sound crazy but it does loop because i put it in loop. I knew that the proper solution would be diafol's answer. But i dont know how i could use a for loop since i use $.each( data, function( i, data )in the first place.

if( data.length )
            {
                $.each( data, function( i, data )
                {
                 html = '<span>#'+i+'</span>';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.