Check strings for "!"

I have, that’s the sad thing.

Stole my leadup @astv99. lol

I’ll keep trying… :cry:

Well let me just post you the difference between an intense and non-intense sentence using split using what @astv99 posted.

The first console will spit out ["hell", "oworld", "", "", ""] This is not an intense sentence.
The second console will spit out ["helloworld", "", "", ""] This is an intense sentence!!!

See a difference yet?

No, I totally understand and am now trying to find whether the first two elements of the array are empty strings or not? I don’t know. Is this normal to be so stuck? I feel like a subhuman.

Don’t be demeaning of yourself.

Your goals have slightly changed but are still similar. Instead of:

  1. !!! or more at the end
  2. No ! in the middle

You’re goal is now

  1. find at least 3 empty strings at then due to split not finding any chars after the !'s
  2. Make sure that the 1st string in the array is the only non-empty string

logic in code not in that specific order

1 Like

If have this, but it doesn’t take care of the three “!” yet.

function intenseString(str) {
  arr = str.split("!");
  if(arr[1] === ""){
      return true;
  } else {
      if(arr[2] === "")
      return false;
      else
      return true;
  }
}

Ah, didn’t read that in the instructions.
I’ll go fix that then.

This doesn’t work?

function intenseString(str) {
  arr = str.split("!");
  if(arr[1] === ""){
      return true;
  } else {
      if(arr[2] || arr.slice(-2) === "")
      return false;
      else
      return true;
  }
}

Nope.

So at this point, a for loop going backwards would be nice. Since all but the element at index 0 should be empty strings. If not, we’ve got a non-intense sentence.

But I don’t need a for loop. I’m complicating it for myself then.

A few things to note: the first element in an array is at index 0, not index 1. You should also check the first and second elements on the same line to streamline your logic, not on separate lines.

JavaScript has a helper string function called endsWith that’s perfect for checking the end…

I know, that’s why I put 2.

A for loop would make your life easier though.

I want to know the easiest way to solve it. If I complicate it, I’ll have a tough time learning it.

There are a few reasons this doesn’t work—it’s incomplete (you don’t have full Boolean expressions on either side of the OR operator), and you’re not checking for at least 3 exclamation points. As I said, using the endsWith() method is perfect for the job here…

function intenseString(str) {
  arr = str.split("!");
  if(arr[1] === ""){
      return true;
  } else {
      if(arr[2] === "" || arr.slice(-2) === "")
      return false;
      else
      return true;
  }
}

Not quite solved it with three “!”

1 Like

Just note that endsWith() is a string method. Not an array method.

Okay, if you don’t want a forloop, do what @astv99 is showing you.

I’ll withdraw then. I believe I am the least experienced so good luck @rstorms!

Someone just tell me. It’s too much time on this one problem. I tried slicing the end of the array but realized all of the arrays will have two empty quotes. I’m really lost now.