Aim / उद्देश्य

Create a calculator for addition, subtraction, and multiplication. / जोड़, घटाव और गुणा करने वाला calculator बनाना।

Result appears here. / परिणाम यहाँ दिखाई देगा।

Program / प्रोग्राम

function calc(op) {
  const a = Number(document.querySelector("#n1").value);
  const b = Number(document.querySelector("#n2").value);
  let result;

  if (op === "add") result = a + b;
  else if (op === "subtract") result = a - b;
  else if (op === "multiply") result = a * b;

  document.querySelector("#result").textContent = `Result = ${result}`;
}

Example output / उदाहरण: Inputs 12 and 3: Add → 15; Subtract → 9; Multiply → 36.

Correction / सुधार: The uploaded source contains op = = '+' , which is invalid syntax. Use strict comparison such as op === "add". The multiplication button should pass a clear operation name, not #.

← All additional practicals