text: const plays = {
      "hamlet": {
          "name": "Hamlet",
          "type": "tragedy"
      },
      "as-like": {
          "name": "As You Like It",
          "type": "comedy"
      },
      "othello": {
          "name": "Othello",
          "type": "tragedy"
      }
  };
  
  const invoice = {
      customer: "BigCo",
      performances: [{
              playID: "hamlet",
              audience: 55
          },
          {
              playID: "as-like",
              audience: 35
          },
          {
              playID: "othello",
              audience: 40
          }
      ]
  };
  
  function statement(invoice, plays) {
      let totalAmount = 0;
      let volumeCredits = 0;
      let result = `Statement for ${invoice.customer}\n`;
  
      for (let perf of invoice.performances) {
          let thisAmount = amountFor(perf, playFor(perf));
  
          // 计算会员积分
          volumeCredits += volumeCreditsFor(perf);
  
          // 打印单剧目账单信息
          result += `  ${playFor(perf).name}: ${usd(thisAmount/100)} (${perf.audience} seats)\n`;
          totalAmount += thisAmount;
      }
      
      result += `Amount owed is ${usd(totalAmount/100)}\n`;
      result += `You earned ${volumeCredits} credits\n`;
      console.log(result)
      return result;
  
      // 内联变量
      function playFor(aPerformance) {
          return plays[aPerformance.playID];
      }
  
      // 提炼函数
      // 计算一场戏剧演出的费用
      function amountFor(aPerformance) {
          let result = 0;
          switch (playFor(aPerformance).type) {
              case "tragedy":
                  result = 40000;
                  if (aPerformance.audience > 30) {
                      result += 1000 * (aPerformance.audience - 30);
                  }
                  break;
              case "comedy":
                  result = 30000;
                  if (aPerformance.audience > 20) {
                      result += 10000 + 500 * (aPerformance.audience - 20);
                  }
                  result += 300 * aPerformance.audience;
                  break;
              default:
                  throw new Error(`unknown type: ${playFor(aPerformance).type}`);
          }
          return result;
      }
  
      // 提炼函数
      // 计算会员积分
      function volumeCreditsFor(aPerformance) {
          let result = 0;
          result += Math.max(aPerformance.audience - 30, 0);
          // add extra credit for every ten comedy attendees
          if ("comedy" === playFor(aPerformance).type) result += Math.floor(aPerformance.audience / 5);
          return result;
      }
  
      // 提炼函数
      // 转换金额单位
      // 改变函数声明
      // format → formatAsUSD → usd
      function usd(aNumber) {
          return new Intl.NumberFormat("en-US", {
              style: "currency",
              currency: "USD",
              minimumFractionDigits: 2
          }).format(aNumber);
      }
  }
  statement(invoice, plays)