Run JavaScript Code

Published by Kálmán Vilisics in

Create a method that takes JavaScript code and returns the output of that code.

Examples

runJS("3*3/2") ➞ 4.5

String code="
  var a=10;
  var b=20;
  isGreater(a, b);
  function isGreater(a, b) {
    return a>b
  }";
runJS(code) ➞ false

runJS("var =13") ➞ "Error at line:1 col:4"

Notes

Check the Resources tab if you're stuck.

Watch a quick demo on how Edabit works.