iTurki
iTurki

Reputation: 16398

creating a for-loop using Javascript?

I have a problem creating a for-loop using Javascript. It seems everyting is fine for me but still I didn't get what I want.

Take a look please to this code to understand more:

The problem is not clear for me. However, when I try to comment out the for-loop, everything works fine !

Any ideas?

Upvotes: 1

Views: 2001

Answers (2)

Aaron
Aaron

Reputation: 11673

There is also an Object-oriented solution to this.

var generate = {
   loop: function() {
        var code = ""+document.myform.inputtext.value;

        if (document.myform.options[0].checked) {
            document.myform.outputtext.value = escape(code);
        }
        else {
            var result= "2- ";
            //CHANGE THE INT(I assume Java) DATATYPE TO A LOCAL VARIABLE USING THE var KEYWORD TO KEEP THE SCOPE IN THE FOR LOOP
            //RECURSION CAN BE QUICKER
            for(var i=0; i<code.length; i++) {
            //There will be some logic to decide if to add the char or not.
            result+=code.charAt(i);
        }
        document.myform.outputtext.value = result;
     }
 }

generate.loop();

Upvotes: 0

Guffa
Guffa

Reputation: 700362

There is no int data type in Javascript (or any data types at all used to declare variables).

for(var i=0; i<code.length; i++) {

Upvotes: 8

Related Questions