Ask coding questions

← Back to all posts
JavaScript Problem
ia13ru (43)

What is wrong with this code? I am not sure.
Javascript:

function check(){
  var code;
  var text = document.createElement("div");
  for(var i = 0; i < 49; i++){
    code = document.querySelector("textarea").value.split("\n")[i];
    var c;
    var finalcode;
    finalcode = code;
    if(finalcode=="x"&&i==0){
      //error = false;
      text.innerHTML = "TEST";
      document.getElementById("output").appendChild(text);
    }
}

Html:

<textarea id="codeBox" rows="50" cols="100">
x
</textarea>
        <div class="div2", id="output">
        </div>

and css is used for the div class.

Answered by 19wintersp (1121) [earned 5 cycles]
View Answer
Comments
hotnewtop
19wintersp (1121)

You're missing a closing bracket for your for loop.

Coder100 (16757)

the problem is you put your code in a function called check but no where in your snippet do you actually call that function.
Call that function:

check();
ia13ru (43)

@Coder100 Sorry, I forgot to include the button which runs the function.

Coder100 (16757)

first you might want to remove the , that's not supposed to be there

ia13ru (43)

@Coder100 Thanks, I have used your advice