1

I am making a Leetspeak converter program, but the second textarea does not show any output. Here is my rudimentary code:

    <!DOCTYPE html>
    <html>
    <body>

    <h1>Leetspeak Converter</h1>

    <script language="JavaScript">
    function convert(){
      var x = document.getElementById("myTextArea").value;
      var result='';
      for (var i = 0, len = x.length; i < len; i++) {
        if (x.charAt(i)=='A'){
          result = result + '4';
        }
      }
      document.getElementById('resultTextarea').value = result ;
    }
    </script>

    <div class="input">
    <textarea id = "myTextArea" rows = "6" cols = "80">
    </textarea>
    </div>

    <div class="push">
    <button onclick="convert">Convert</button>
    </div>

    <div class="result">
    <textarea id = "resultTextArea" rows = "6" cols = "80">
    </textarea>
    </div>

It does not produce any output at all. I have tried using console.log(), but it shows no output. I have also used a debugger, but no dice.

3 Answers 3

2

You have syntax errors, in 2 parts, so change this

<button onclick="convert">Convert</button> // this does not represent a method

with this

<button onclick="convert()">Convert</button>

and in addition, this

document.getElementById('resultTextarea').value = result ; // a small typo in id

with this

document.getElementById('resultTextArea').value = result ;

function convert(){
      var x = document.getElementById("myTextArea").value;
      var result=0;
      for (var i = 0, len = x.length; i < len; i++) {
        if (x.charAt(i)=='A'){
          result = result + 4;
        }
      }
      document.getElementById('resultTextArea').value = result ;
    }
<div class="input">
    <textarea id = "myTextArea" rows = "6" cols = "80">
    </textarea>
    </div>

    <div class="push">
    <button onclick="convert()">Convert</button>
    </div>

    <div class="result">
    <textarea id = "resultTextArea" rows = "6" cols = "80">
    </textarea>
    </div>

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you a lot. Can you point out what errors I made, so I can avoid them in the future. I am new.
@toyotasupra minor issues that could happen if you work late and your eyes are tired :)
Yes, I am only 13 but code like hell, all the time, so I have been in that situation tons of times.
1

You have syntax error in:

<button onclick="convert">Convert</button>

Fixed this as:

<button onclick="convert()">Convert</button>

Comments

1

try this

<!DOCTYPE html>
    <html>
    <body>

    <h1>Leetspeak Converter</h1>

    <script language="JavaScript">
    function convert(){
      var x = document.getElementById("myTextArea").value;

      var result='';


      for (var i = 0,len = x.length ; i < len; i++) {
        if (x.charAt(i)=='A'){
          result = result + '4';
        }
      }

      document.getElementById('resultTextArea').value = result ;
    }
    </script>

    <div class="input">
    <textarea id = "myTextArea" rows = "6" cols = "80">
    </textarea>
    </div>

    <div class="push">
    <button onclick="convert()">Convert</button>
    </div>

    <div class="result">
    <textarea id = "resultTextArea" rows = "6" cols = "80">
    </textarea>
    </div>
    </body>
    </html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.