How to input multiple lines in WebKit JavaScriptCore shell?

12 Views Asked by At

Is there a way for input multiple lines in WebKit JavaScriptCore shell? For example, I want to type a function declaration that has multiple lines. When I just copy and paste the function, the exception shows as follows.

>>> function add(n) {
    let result = 0;
    for(var i=0; i<=n; i++) {
        result += n;
    }
    return result;
}Exception: SyntaxError: Parser error
>>> Exception: SyntaxError: Can't create duplicate variable: 'result'
>>> Exception: SyntaxError: Unexpected end of script
>>> Exception: ReferenceError: Can't find variable: n
>>> Exception: SyntaxError: Parser error
>>> Exception: SyntaxError: Return statements are only valid inside functions

I can not find a solution for it.

0

There are 0 best solutions below