0% found this document useful (0 votes)
2 views3 pages

JavaScript Window Prompt Arithmetic Examples

The document provides beginner examples of using window.prompt() in JavaScript to take user input for basic arithmetic operations such as addition, subtraction, multiplication, and division. Each example demonstrates how to convert the input from text to a number using Number() for calculations. Additionally, there is an example that showcases multiple operations performed on two numbers.

Uploaded by

p10604302
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

JavaScript Window Prompt Arithmetic Examples

The document provides beginner examples of using window.prompt() in JavaScript to take user input for basic arithmetic operations such as addition, subtraction, multiplication, and division. Each example demonstrates how to convert the input from text to a number using Number() for calculations. Additionally, there is an example that showcases multiple operations performed on two numbers.

Uploaded by

p10604302
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JavaScript Beginner Examples – window.

prompt()
NOTE:
[Link]() is used to take input from the user.
The value entered is always treated as TEXT, so we use Number() to convert it into a
number for calculations.

Example 1: Addition using [Link]()

<!DOCTYPE html>
<html>
<body>

<script>
var num1 = Number([Link]("Enter first number:"));
var num2 = Number([Link]("Enter second number:"));

var sum = num1 + num2;

[Link]("First Number: " + num1 + "<br>");


[Link]("Second Number: " + num2 + "<br>");
[Link]("Sum: " + sum);
</script>

</body>
</html>

Example 2: Subtraction using [Link]()

<!DOCTYPE html>
<html>
<body>

<script>
var a = Number([Link]("Enter a number:"));
var b = Number([Link]("Enter another number:"));

var result = a - b;

[Link]("Result of Subtraction: " + result);


</script>
</body>
</html>

Example 3: Multiplication using [Link]()

<!DOCTYPE html>
<html>
<body>

<script>
var x = Number([Link]("Enter first value:"));
var y = Number([Link]("Enter second value:"));

var multiply = x * y;

[Link]("Multiplication Result: " + multiply);


</script>

</body>
</html>

Example 4: Division using [Link]()

<!DOCTYPE html>
<html>
<body>

<script>
var dividend = Number([Link]("Enter dividend:"));
var divisor = Number([Link]("Enter divisor:"));

var division = dividend / divisor;

[Link]("Division Result: " + division);


</script>

</body>
</html>
Example 5: Multiple Operations using [Link]()

<!DOCTYPE html>
<html>
<body>

<script>
var num1 = Number([Link]("Enter first number:"));
var num2 = Number([Link]("Enter second number:"));

[Link]("Addition: " + (num1 + num2) + "<br>");


[Link]("Subtraction: " + (num1 - num2) + "<br>");
[Link]("Multiplication: " + (num1 * num2) + "<br>");
[Link]("Division: " + (num1 / num2));
</script>

</body>
</html>

You might also like