Learn Basic OOP by Building a Shopping Cart - Step 55

Tell us what’s happening:

Hello Everyone,
I got stuck at this level for some minutes now. After several attempts, I keep getting the same result. The instruction to this step is vivid and I have written my code exactly, as it is described, but I am still stuck. This is the instruction:

The first thing you should do is check if the items array is empty. If it is, display an alert to the user with the text Your shopping cart is already empty, then return from the function.

Remember that 0 is a falsy value, so you can use the ! operator to check if the array is empty.

After displaying the alert, return from the function to stop execution.

Can Someone please point out, what I am missing? Your time and services will highly be appreciated!

below are some of my attempts:

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

  clearCart() {
    if(this.items !== " ") {
      alert("Your shopping cart is already empty");
      return;
    }
  }

//two

clearCart() {
   if (!items) {
       alert("Your shopping cart is already empty";
       return;
   }
}

// three
clearCart() {
   if (!(this.items)) {
       alert("Your shopping cart is already empty";
       return;
   }
}

//four

clearCart() {
    if(!(this.items) === "") {
      alert("Your shopping cart is already empty");
      return;
    }
  }

//five
clearCart() {
    if(this.items = !"") {
      alert("Your shopping cart is already empty");
      return;
    }
  }

//six

clearCart() {
    if(this.items != 0) {
      alert("Your shopping cart is already empty");
      return;
    }
  }

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36

Challenge Information:

Learn Basic OOP by Building a Shopping Cart - Step 55

I used the “this” keyword because, items is defined in the constructor

hi there,

is your code above correct? It looks like you have duplicated the method?

to check if the array is empty, try using the .length property

I currently have the last(sixth) line of code block on my screen. Those are just some of the attempts I have been wresting with for some minutes now.

Thanks man. Much appreciated

1 Like