javascript 由iamuchejude创建的Andela购物车测试 - https://repl.it/@iamuchejude/Andela-Shopping-Cart-Test

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 由iamuchejude创建的Andela购物车测试 - https://repl.it/@iamuchejude/Andela-Shopping-Cart-Test相关的知识,希望对你有一定的参考价值。

class ShoppingCart {
  constructor() {
    this.quantity = 100;
    this.total = 0;
    this.items = {};
  }
  
  addItem(item_name, quantity, price) {
      this.total += price * quantity;
      this.items[item_name] = quantity
  }
  
  removeItem(item_name, quantity, price)  {
    if(this.items[item_name] in this.items) {
      return 'Item is not in cart';
    } else {
      this.total -= price * quantity;  
      this.items[item_name] = this.items[item_name] - quantity; 
    } 
  }
  
  checkout(cash_paid) {
    if(cash_paid < this.total) {
      return 'Cash paid not enough';
    } else {
      return cash_paid - this.total;
    }
  }
}

class Shop extends ShoppingCart {
  removeItem() {
    this.quantity -= 1;
    return this.quantity;
  }
}

以上是关于javascript 由iamuchejude创建的Andela购物车测试 - https://repl.it/@iamuchejude/Andela-Shopping-Cart-Test的主要内容,如果未能解决你的问题,请参考以下文章

javascript Andela删除iamuchejude创建的Javascript中的重复测试 - https://repl.it/@iamuchejude/Andelas-remove-dup

仅使用javascript检查由javascript创建的元素是不是存在[重复]

使用 selenium webdriver 定位由 javascript 创建的元素

由javascript创建的css动画[关闭]

Propel: 由Node.js之父创建的JavaScript科学计算库

javascript binarySearchTree由plastikaweb创建 - https://repl.it/@plastikaweb/binarySearchTree