Aim / उद्देश्य

Take two numbers from the user and display their sum. / User से दो numbers लेकर उनका sum दिखाना।

Result: —

Program / प्रोग्राम

const a = Number(document.querySelector("#first").value);
const b = Number(document.querySelector("#second").value);
const sum = a + b;
document.querySelector("#result").textContent = `Sum = ${sum}`;

Example output / उदाहरण: For 12 and 8, the output is Sum = 20.

Correction / सुधार: Use prompt("Enter first number") to ask for text. The uploaded source mistakenly tried Number("Enter first number"), which converts the literal words—not user input—to a number and results in NaN. This example uses inputs so students can see the values.

← All additional practicals