
Practice 100 JavaScript Maths Programming Questions
Q1. Write a JavaScript program to calculate the sum of two numbers.
Input: a = 5, b = 3
Expected Output: 8
Q2. Write a JavaScript program to find the difference between two numbers.
Input: a = 10, b = 4
Expected Output: 6
Q3. Write a JavaScript program to multiply two numbers.
Input: a = 6, b = 7
Expected Output: 42
Q4. Write a JavaScript program to divide two numbers.
Input: a = 20, b = 4
Expected Output: 5
Q5. Write a JavaScript program to find the modulus of two numbers.
Input: a = 25, b = 7
Expected Output: 4
Q6. Write a JavaScript program to calculate the power of a number.
Input: base = 3, exponent = 2
Expected Output: 9
Q7. Write a JavaScript program to calculate the square root of a number.
Input: a = 16
Expected Output: 4
Q8. Write a JavaScript program to calculate the cube root of a number.
Input: a = 27
Expected Output: 3
Q9. Write a JavaScript program to round a number to the nearest integer.
Input: a = 5.67
Expected Output: 6
Q10. Write a JavaScript program to find the largest of three numbers.
Input: a = 5, b = 10, c = 8
Expected Output: 10
Q11. Write a JavaScript program to find the smallest of three numbers.
Input: a = 5, b = 10, c = 8
Expected Output: 5
Q12. Write a JavaScript program to calculate the area of a rectangle.
Input: length = 8, width = 4
Expected Output: 32
Q13. Write a JavaScript program to calculate the area of a circle.
Input: radius = 7
Expected Output: 153.93804002589985
Q14. Write a JavaScript program to calculate the circumference of a circle.
Input: radius = 7
Expected Output: 43.982297150257104
Q15. Write a JavaScript program to calculate the area of a triangle.
Input: base = 6, height = 8
Expected Output: 24
Q16. Write a JavaScript program to calculate the perimeter of a rectangle.
Input: length = 8, width = 5
Expected Output: 26
Q17. Write a JavaScript program to find the factorial of a number.
Input: a = 5
Expected Output: 120
Q18. Write a JavaScript program to find the greatest common divisor (GCD) of two numbers.
Input: a = 24, b = 36
Expected Output: 12
Q19. Write a JavaScript program to find the least common multiple (LCM) of two numbers.
Input: a = 12, b = 18
Expected Output: 36
Q20. Write a JavaScript program to check if a number is prime.
Input: a = 11
Expected Output: true
Q21. Write a JavaScript program to check if a number is even.
Input: a = 6
Expected Output: true
Q22. Write a JavaScript program to check if a number is odd.
Input: a = 7
Expected Output: true
Q23. Write a JavaScript program to find the sum of digits of a number.
Input: a = 1234
Expected Output: 10
Q24. Write a JavaScript program to reverse a number.
Input: a = 1234
Expected Output: 4321
Q25. Write a JavaScript program to calculate the area of a trapezoid.
Input: a = 5, b = 10, height = 4
Expected Output: 30
Q26. Write a JavaScript program to calculate the volume of a cylinder.
Input: radius = 5, height = 10
Expected Output: 785.3981633974483
Q27. Write a JavaScript program to find the distance between two points on a plane.
Input: x1 = 1, y1 = 1, x2 = 4, y2 = 5
Expected Output: 5
Q28. Write a JavaScript program to check if a number is a perfect square.
Input: a = 16
Expected Output: true
Q29. Write a JavaScript program to check if a number is a perfect cube.
Input: a = 27
Expected Output: true
Q30. Write a JavaScript program to calculate the sum of squares of two numbers.
Input: a = 3, b = 4
Expected Output: 25
Q31. Write a JavaScript program to calculate the sum of cubes of two numbers.
Input: a = 2, b = 3
Expected Output: 35
Q32. Write a JavaScript program to calculate the distance between two points in 3D space.
Input: x1 = 1, y1 = 1, z1 = 1, x2 = 4, y2 = 5, z2 = 6
Expected Output: 7.07106781187
Q33. Write a JavaScript program to convert a number to its binary form.
Input: a = 10
Expected Output: 1010
Q34. Write a JavaScript program to convert a number to its hexadecimal form.
Input: a = 255
Expected Output: ff
Q35. Write a JavaScript program to convert a number to its octal form.
Input: a = 8
Expected Output: 10
Q36. Write a JavaScript program to find the nth Fibonacci number.
Input: n = 6
Expected Output: 8
Q37. Write a JavaScript program to calculate the sum of the first n natural numbers.
Input: n = 5
Expected Output: 15
Q38. Write a JavaScript program to calculate the product of the first n natural numbers.
Input: n = 4
Expected Output: 24
Q39. Write a JavaScript program to find the power of 10 raised to a number.
Input: a = 4
Expected Output: 10000
Q40. Write a JavaScript program to calculate the compound interest.
Input: principal = 1000, rate = 5, time = 2
Expected Output: 1025
Q41. Write a JavaScript program to calculate simple interest.
Input: principal = 1000, rate = 5, time = 2
Expected Output: 100
Q42. Write a JavaScript program to calculate the factorial of a number using recursion.
Input: a = 5
Expected Output: 120
Q43. Write a JavaScript program to calculate the area of a sector.
Input: radius = 7, angle = 60
Expected Output: 25.1327412287
Q44. Write a JavaScript program to calculate the perimeter of a circle.
Input: radius = 7
Expected Output: 43.982297150257104
Q45. Write a JavaScript program to calculate the circumference of an ellipse.
Input: a = 5, b = 3
Expected Output: 25.1327412287
Q46. Write a JavaScript program to find the sum of the squares of the first n natural numbers.
Input: n = 5
Expected Output: 55
Q47. Write a JavaScript program to calculate the sum of the cubes of the first n natural numbers.
Input: n = 3
Expected Output: 36
Q48. Write a JavaScript program to calculate the sum of all even numbers up to n.
Input: n = 10
Expected Output: 30
Q49. Write a JavaScript program to calculate the sum of all odd numbers up to n.
Input: n = 10
Expected Output: 25
Q50. Write a JavaScript program to calculate the hypotenuse of a right-angled triangle.
Input: a = 3, b = 4
Expected Output: 5
Q51. Write a JavaScript program to find the factorial of a number using a loop.
Input: a = 6
Expected Output: 720
Q52. Write a JavaScript program to calculate the number of days between two dates.
Input: startDate = "2024-01-01", endDate = "2024-01-10"
Expected Output: 9
Q53. Write a JavaScript program to calculate the number of leap years between two years.
Input: startYear = 2000, endYear = 2020
Expected Output: 5
Q54. Write a JavaScript program to calculate the angle between two hands of a clock.
Input: hour = 3, minute = 15
Expected Output: 7.5
Q55. Write a JavaScript program to calculate the speed of a moving object given distance and time.
Input: distance = 100, time = 2
Expected Output: 50
Q56. Write a JavaScript program to calculate the area of a parallelogram.
Input: base = 5, height = 3
Expected Output: 15
Q57. Write a JavaScript program to calculate the area of an ellipse.
Input: a = 5, b = 3
Expected Output: 47.12388980384689
Q58. Write a JavaScript program to convert Celsius to Fahrenheit.
Input: celsius = 25
Expected Output: 77
Q59. Write a JavaScript program to convert Fahrenheit to Celsius.
Input: fahrenheit = 77
Expected Output: 25
Q60. Write a JavaScript program to find the area of a hexagon.
Input: side = 6
Expected Output: 93.5307436097982
Q61. Write a JavaScript program to calculate the perimeter of a hexagon.
Input: side = 6
Expected Output: 36
Q62. Write a JavaScript program to calculate the perimeter of a rhombus.
Input: side = 4
Expected Output: 16
Q63. Write a JavaScript program to find the mean of an array of numbers.
Input: arr = [1, 2, 3, 4, 5]
Expected Output: 3
Q64. Write a JavaScript program to find the median of an array of numbers.
Input: arr = [1, 3, 2, 4, 5]
Expected Output: 3
Q65. Write a JavaScript program to find the mode of an array of numbers.
Input: arr = [1, 2, 2, 3, 4, 5]
Expected Output: 2
Q66. Write a JavaScript program to calculate the standard deviation of an array of numbers.
Input: arr = [1, 2, 3, 4, 5]
Expected Output: 1.4142135623730951
Q67. Write a JavaScript program to calculate the harmonic mean of an array of numbers.
Input: arr = [1, 2, 3, 4]
Expected Output: 1.92
Q68. Write a JavaScript program to calculate the geometric mean of an array of numbers.
Input: arr = [1, 2, 3, 4]
Expected Output: 2.213363839400643
Q69. Write a JavaScript program to calculate the area of an octagon.
Input: side = 4
Expected Output: 86.60254037844385
Q70. Write a JavaScript program to calculate the area of a polygon.
Input: sides = 5, length = 6
Expected Output: 61.93718642120281
Q71. Write a JavaScript program to calculate the volume of a cone.
Input: radius = 3, height = 5
Expected Output: 47.12388980384689
Q72. Write a JavaScript program to calculate the volume of a sphere.
Input: radius = 3
Expected Output: 113.097335
Q73. Write a JavaScript program to calculate the volume of a pyramid.
Input: baseArea = 16, height = 6
Expected Output: 32
Q74. Write a JavaScript program to calculate the surface area of a sphere.
Input: radius = 3
Expected Output: 113.097335
Q75. Write a JavaScript program to calculate the surface area of a cylinder.
Input: radius = 3, height = 5
Expected Output: 150.796447
Q76. Write a JavaScript program to calculate the volume of a rectangular prism.
Input: length = 3, width = 4, height = 5
Expected Output: 60
Q77. Write a JavaScript program to calculate the area of a right triangle.
Input: base = 4, height = 5
Expected Output: 10
Q78. Write a JavaScript program to find the angle of a triangle given its sides.
Input: a = 5, b = 6, c = 7
Expected Output: 50.24
Q79. Write a JavaScript program to convert radians to degrees.
Input: radians = 1
Expected Output: 57.29577951308232
Q80. Write a JavaScript program to convert degrees to radians.
Input: degrees = 45
Expected Output: 0.7853981633974483
Q81. Write a JavaScript program to calculate the area of a sector.
Input: radius = 5, angle = 60
Expected Output: 13.0907
Q82. Write a JavaScript program to calculate the perimeter of a rhombus.
Input: side = 5
Expected Output: 20
Q83. Write a JavaScript program to calculate the area of a rhombus.
Input: diagonal1 = 6, diagonal2 = 8
Expected Output: 24
Q84. Write a JavaScript program to calculate the volume of a tetrahedron.
Input: side = 4
Expected Output: 15.464
Q85. Write a JavaScript program to calculate the area of an isosceles triangle.
Input: base = 6, height = 4
Expected Output: 12
Q86. Write a JavaScript program to calculate the area of a kite.
Input: diagonal1 = 5, diagonal2 = 8
Expected Output: 20
Q87. Write a JavaScript program to calculate the total surface area of a cylinder.
Input: radius = 7, height = 10
Expected Output: 754.0
Q88. Write a JavaScript program to calculate the area of a sector.
Input: radius = 7, angle = 60
Expected Output: 25.1327412287
Q89. Write a JavaScript program to calculate the length of an arc of a circle.
Input: radius = 7, angle = 60
Expected Output: 7.3303828585
Q90. Write a JavaScript program to calculate the volume of a rectangular prism.
Input: length = 10, width = 5, height = 2
Expected Output: 100
Q91. Write a JavaScript program to calculate the perimeter of a parallelogram.
Input: length = 10, width = 4
Expected Output: 28
Q92. Write a JavaScript program to find the cube of a number.
Input: a = 3
Expected Output: 27
Q93. Write a JavaScript program to calculate the distance between two points.
Input: x1 = 3, y1 = 4, x2 = 6, y2 = 8
Expected Output: 5
Q94. Write a JavaScript program to calculate the sum of squares of two numbers.
Input: a = 2, b = 4
Expected Output: 20
Q95. Write a JavaScript program to calculate the sum of cubes of two numbers.
Input: a = 3, b = 2
Expected Output: 35
Q96. Write a JavaScript program to calculate the volume of a sphere.
Input: radius = 4
Expected Output: 268.082573106329
Q97. Write a JavaScript program to find the area of a quadrilateral.
Input: length = 5, width = 7
Expected Output: 35
Q98. Write a JavaScript program to calculate the area of an equilateral triangle.
Input: side = 6
Expected Output: 15.588457268119896
Q99. Write a JavaScript program to calculate the volume of a cylinder.
Input: radius = 5, height = 8
Expected Output: 628.3185307179586
Q100. Write a JavaScript program to calculate the area of a circle.
Input: radius = 10
Expected Output: 314.1592653589793