JAVASCRIPT CODING A) Write a function named sum3 that accepts three arguments an
ID: 3716018 • Letter: J
Question
JAVASCRIPT CODING
A) Write a function named sum3 that accepts three arguments
and returns their sum.
Examples:
sum3( 4, 3, 9) => 16
sum3(-5, 12, 7) => 14
B) Write a function named mult3 that accepts three arguments
and returns their product.
Examples:
mult3( 4, 3, 9) => 108
mult3(-5, 12, 7) => -420
C) Write a function named pow that accepts two arguments (a
base and an exponent) and returns the first number raised to the
second number.
Examples:
pow(2, 3) => 8
pow(3, 2.5) => 15.588457268119896
D) Write a function named milesToInches that accepts a
number representing miles, and returns the number of inches in
that many miles.
Examples:
milesToInches(6) => 380160
milesToInches(2.5) => 158400
E) Our class has 145 students. If each student does a fist-bump
with each other student, how many fist-bumps are there
altogether? Write a function named fb_total that accepts the
number of students and returns the total number of fist-bumps.
Examples:
fb_total(6) =>15
fb_total(40) = 780
F) Write a function named vol_sphere that accepts a radius and
returns the volume. Use Math.PI.
Examples:
vol_sphere(8) => 2144.66
vol_sphere(Math.PI) => 129.88
G) Write a function isEven that accepts a number n, and returns
true if n is even, false otherwise.
Examples:
isEven(111) => false
isEven(42) => true
Explanation / Answer
Following is the answer:
1) Write a function named sum3 that accepts three arguments and returns their sum.
function sum3(x, y, z) {
return x+y+z;
}
B) Write a function named mult3 that accepts three arguments and returns their product.
function mul3(x, y, z) {
return x*y*z;
}
C) Write a function named pow that accepts two arguments (a base and an exponent) and returns the first number raised to the second number.
function pow(x,y){
return Math.pow(x, y);
}
D) Write a function named milesToInches that accepts a number representing miles, and returns the number of inches in that many miles.
function milesToinches(x){
return x*63360;
}
F) Write a function named vol_sphere that accepts a radius and returns the volume. Use Math.PI.
function vol_sphere(radius)
{
var volume;
radius = Math.abs(radius);
volume = (4/3) * Math.PI * Math.pow(radius, 3);
volume = volume.toFixed(4);
return volume;
}
G) Write a function isEven that accepts a number n, and returns true if n is even, false otherwise.
function isEven(n){
return (n % 2 == 0);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.