JavaScript: Calculate multiplication and division of two numbers
JavaScript Basic: Exercise-10 with Solution
Multiplication and Division (User Input)
Write a JavaScript program to calculate multiplication and division of two numbers (input from the user).
Sample Form:

Visual Presentation:

Sample Solution:
HTML Code:
The JavaScript program prompts the user to input two numbers and then calculates and displays their multiplication and division results. It uses prompt to get the user inputs and basic arithmetic operations to compute the results, which are then logged to the console.
JavaScript Code:
Live Demo:
Explanation:
document.getElementById(id).value: The value property sets or returns the value of the value attribute of a text field.
document.getElementById("result").innerHTM : The innerHTML property sets or returns the HTML content (inner HTML) of an element.
ES6 Version:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that takes two user inputs and returns both the product and quotient rounded to two decimal places.
- Write a JavaScript program that handles division by zero while computing the product and quotient of two user-provided numbers.
- Write a JavaScript program that performs multiplication and division based on user input, returning a custom error message for invalid inputs.
Improve this sample solution and post your code through Disqus.
Previous: JavaScript program to calculate number of days left until next Christmas.
Next: JavaScript program to convert temperatures to and from celsius, fahrenheit.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.