1

I am writing a function that takes on a string "str," and checks if the string has every letter surrounded by + (add) symbols. If every letter on the string is indeed surrounded by +s, like +b+, it must return true, else false.

 function SimpleSymbols(str) { 
    var array1 = str.split("");
    var arrayABC = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

      var check = function(name, index){
        if (typeOf().arrayABC.indexOf(name[index]) === "number"){
            if (name[index-1] === "+" && name[index+1] === "+"){
                return true;
            } else {
                return false;
            };
        };  
      };
    return array1.forEach(check)     
};

I am getting "SyntaxError: Unexpected token ," as a result.

4
  • I recommend to read a JS tutorial to make yourself more familiar with JS' syntax: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide Commented May 13, 2015 at 20:35
  • Did some rework Felix. Could you help me out? Commented May 13, 2015 at 20:54
  • Have a look at developer.chrome.com/devtools/docs/console and developer.chrome.com/devtools/docs/javascript-debugging. They explain how to use Chrome's debugger tools and console to debug your code. The console will tell you exactly in which line the error is. Look at that line and compare the syntax to what is shown in the MDN reference or JS guide. Then make the necessary adjustments to produce valid JS. Commented May 13, 2015 at 21:07
  • Also please don't change your question like this. The given answer doesn't make sense anymore in this new context. If you have a new problem, ask a new question. However, Stack Overflow if not for debugging your code. Learn how to use the right tools in order to do that on your own. Commented May 13, 2015 at 21:10

1 Answer 1

3
{'a', 'b', ...}

is not a valid object or array literal. If you want to create an array, use square brackets:

['a', 'b', ...]

Learn more about the basics of arrays on MDN.

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

1 Comment

Thank you very muck Felix. Starting out is not easy, and sometimes these things go overlooked. Cheers.

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.