How do I run javascript code from a HTML input box?


I am currently trying to run JavaScript code from a HTML input box for my online code compiler project.

function runCode(){
     let code = document.getElementById('code').value

I was expecting it to actually run the code instead of just logging it as a string

>Solution :

Use eval()

run.onclick =() => {
<textArea id="editor">console.log('test')</textArea>
<button id="run">run</button>

Leave a ReplyCancel reply