49.2k views
5 votes
Write JavaScript statements or comments to accomplish each of the following the

tasks below:
Part A
1. State that a program will calculate the product of three integers.
2. Declare the variables num1, num2, num3 and result.
3. Declare the variables num1Val, num2Val and num3Val.
4. Prompt the user to enter the first value, read the value from
the user and store it in the variable num1Val.
5. Prompt the user to enter the second value, read the value from
the user and store it in the variable num2Val.
6. Prompt the user to enter the third value, read the value from
the user and store it in the variable Num3Val.
7. Convert num1Val to an integer, and store the result in the
variable num1.
8. Convert num2Val to an integer, and store the result in the
variable num2.
9. Convert num3Val to an integer, and store the result in the
variable num3.
10. Compute the product of the three integers contained in
variables num1, num2 and num3, and assigned the result to
the variable result.
11. Write a line of HTML text containing the string "The product is" [3 marks]
followed by the value result.
Part B
Using the statements written in Part A write a complete program that calculates
and prints the product of three integers

1 Answer

2 votes

Final answer:

PART A:

// This program will calculate the product of three integers.

let num1, num2, num3, result;

let num1Val, num2Val, num3Val;

num1Val = prompt('Enter the first value:');

num2Val = prompt('Enter the second value:');

num3Val = prompt('Enter the third value:');

num1 = parseInt(num1Val, 10);

num2 = parseInt(num2Val, 10);

num3 = parseInt(num3Val, 10);

result = num1 * num2 * num3;

document.write('The product is ' + result);

PART B:

// This program will calculate the product of three integers.
let num1, num2, num3, result;
let num1Val, num2Val, num3Val;
num1Val = prompt('Enter the first value:');
num2Val = prompt('Enter the second value:');
num3Val = prompt('Enter the third value:');
num1 = parseInt(num1Val, 10);
num2 = parseInt(num2Val, 10);
num3 = parseInt(num3Val, 10);
result = num1 * num2 * num3;
document.write('The product is ' + result);

Step-by-step explanation:

To accomplish the tasks for Part A:

  1. Comment indicating the program purpose: // This program will calculate the product of three integers.
  2. Declare the variables: let num1, num2, num3, result;
  3. Declare more variables: let num1Val, num2Val, num3Val;
  4. Prompt user and store value for num1Val: num1Val = prompt('Enter the first value:');
  5. Prompt user and store value for num2Val: num2Val = prompt('Enter the second value:');
  6. Prompt user and store value for num3Val: num3Val = prompt('Enter the third value:');
  7. Convert num1Val to an integer: num1 = parseInt(num1Val, 10);
  8. Convert num2Val to an integer: num2 = parseInt(num2Val, 10);
  9. Convert num3Val to an integer: num3 = parseInt(num3Val, 10);
  10. Compute the product: result = num1 * num2 * num3;
  11. Output the result in HTML: document.write('The product is ' + result);

For Part B, to create a complete program using the above statements:

// This program will calculate the product of three integers.
let num1, num2, num3, result;
let num1Val, num2Val, num3Val;
num1Val = prompt('Enter the first value:');
num2Val = prompt('Enter the second value:');
num3Val = prompt('Enter the third value:');
num1 = parseInt(num1Val, 10);
num2 = parseInt(num2Val, 10);
num3 = parseInt(num3Val, 10);
result = num1 * num2 * num3;
document.write('The product is ' + result);
User Chandu
by
7.6k points