无需输入
使用HTML和JavaScript构建一个计算器。
计算器的HTML代码如下：
<form>
  <input type="text" id="calculator-screen" disabled>
</form>
<button type="button" id="zero" onclick="addNum(0)">0</button>
<button type="button" id="one" onclick="addNum(1)">1</button>
<button type="button" id="two" onclick="addNum(2)">2</button>
<button type="button" id="three" onclick="addNum(3)">3</button>
<button type="button" id="add" onclick="calculate('+')">+</button>
<button type="button" id="subtract" onclick="calculate('-')">-</button>
<button type="button" id="multiply" onclick="calculate('*')">*</button>
<button type="button" id="divide" onclick="calculate('/')">/</button>
<button type="button" id="equal" onclick="calculate('=')">=</button>

计算器的JavaScript代码如下：

function addNum(num) {
  var screen = document.getElementById('calculator-screen');
  screen.value += num;
}

function calculate(sign) {
  var screen = document.getElementById('calculator-screen');
  var result;
  switch(sign) {
    case '+':
      result = eval(screen.value);
      break;
    case '-':
      result = eval(screen.value);
      break;
    case '*':
      result = eval(screen.value);
      break;
    case '/':
      result = eval(screen.value);
      break;
    case '=':
      result = eval(screen.value);
      break;
  }
  screen.value = result;
}