Programming Questions

  • Newest
  • Popular Tags
  • Ask A Question
  • Logical AND instead of OR
    I do not understand the solution with logical OR operator, so I tried using Logical AND but I'm not getting the desired output. Eg +d+=3=+s+ outputs to false, when this is a true condition. After using regex to get a string match, I'm checking if str[i-1] == '+' && str[i+1] == '+' then return true. Hope someone can shed some light on this, thank you very much!
    function SimpleSymbols(str) { 
      // code goes here 
      for(i=0;i<str.length;i++) {
        if (str[i].match(/[a-z]/i !== null)){
            if(str[i-1] !== '+' && str[i+1] !== '+') {
                return true;
      return false;
    // keep this function call here 
    deepMeditation posted this question on 5/3/18 | javascript, logic, simple, symbols
  • +
  • 0
  • -
  • Hi! In the second 'if' statement, you are testing whether the characters are *not* equal to '+', which would mean you encountered a string that fails the test. Try switching the boolean values of your return statements. Good luck!
    Log in to write an answer.