Learn Basic OOP by Building a Shopping Cart - Step 57

Tell us what’s happening:

I don’t know why it’s not working. Error is "You should create an if statement that checks if the user confirmed the prompt. Remember that you can check the truthiness of isCartCleared directly.

Your code so far

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

/* file: styles.css */

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

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

    const isCartCleared = confirm(
      "Are you sure you want to clear all items from your shopping cart?"
    );
    if (isCartCleared) {
    this.items = []; 
    this.total = 0;
  }

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn Basic OOP by Building a Shopping Cart - Step 57

Hello,
Welcome to the Forums :wave:


Your if statement seems correct to me.
However, I noticed that you might not have closed the clearCart() properly which might be causing the tests to fail.

1 Like

Thank you! I missed that part!

1 Like