JavaScript: Compute the sum of the two given integers
JavaScript Basic: Exercise-16 with Solution
Sum Two Integers (Triple if Equal)
Write a JavaScript program to compute the sum of the two given integers. If the two values are the same, then return triple their sum.
This JavaScript program calculates the sum of two given integers. If the two integers are the same, it returns triple their sum. It demonstrates conditional statements to determine whether the integers are equal and to perform the appropriate computation accordingly.
Visual Presentation:

Sample Solution:
JavaScript Code:
Output:
30 60
Live Demo:
Flowchart:

ES6 Version:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that sums two integers and returns triple their sum if the integers are equal.
- Write a JavaScript program that sums two numbers and returns triple the sum if both numbers are prime and identical.
- Write a JavaScript program that calculates the sum of two numbers; if they are equal, return thrice the sum, otherwise add a fixed bonus to the sum.
Improve this sample solution and post your code through Disqus.
Previous: JavaScript program to get the difference between a given number
Next: JavaScript program to compute the absolute difference between a specified number and 19.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics