Sequential function calls in JavaScript

You can also pass the result of one function as a parameter to another, for example, this is how we first find the square of the number 2, and then the square of the result:

javascriptfunction func(num) {
  return num ** 2;
}

let res = func(func(2));
console.log(res); // shows 16

The functions, of course, do not have to be the same. Let, for example, we have a function that returns the square of a number, and a function that returns the cube of a number:

javascriptfunction square(num) {
  return num ** 2;
}

function cube(num) {
  return num ** 3;
}

Let's use these functions to square the number 2, and then cube the result of this operation:

javascriptlet res = cube(square(2));
console.log(res);

Suppose now we have a function that returns the square of a number, and a function that finds the sum of two numbers:

javascriptfunction square(num) {
  return num ** 2;
}

function sum(num1, num2) {
  return num1 + num2;
}

Using these functions, we find the sum of the square of the number 2 and the square of the number 3:

javascriptlet res = sum(square(2), square(3));
console.log(res);
Задание 1

Suppose you have a function that returns the square root of a number, and a function that rounds a fraction to three decimal places:

javascriptfunction sqrt(num) {
  return Math.sqrt(num);
}

function round(num) {
  return num.toFixed(3);
}

Use these functions to find the square root of 2 and round it to three decimal places.

Задание 2

Suppose you have a function that returns the square root of a number and a function that returns the sum of three numbers:

javascriptfunction sqrt(num) {
  return Math.sqrt(num);
}

function sum(num1, num2, num3) {
  return num1 + num2 + num3;
}

Using these functions, find the sum of the roots of the numbers 2, 3 and 4 and write it into the variable res.

Задание 3

Suppose you have a function that rounds a fraction to three decimal places:

javascriptfunction round(num) {
  return num.toFixed(3);
}

Use this function to modify the previous task so that the variable res is set to a fraction rounded to 3 decimal places.