Exercise 2: Functions and uses

Functions and uses

Okay, so... How do we use these functions? How can we do to pass parameters to them and get results?

It's easy! We only have to put the name of the function and, between parentheses, its arguments, just like we've been doing.

function doble(number) {
  return 2 * number
}

function successorOfDoble(number) {
   return doble(number) + 1;
}

Or even better:

function doble(number) {
  return 2 * number
}

function successor(number) {
  return number + 1
}

function successorOfDoble(number) {
   return successor(doble(number));
}

Let's practice! Write the following functions:

  • predecessor: takes a number and returns that number minus one.
  • triple: returns a number times three.
  • predecessorOfTriple: that matches the two previous functions

You must sign in before submitting your solutions

Oops, your solution didn't work

  • Check that your program does not have recursion or an infinite loop
  • Check that you have an internet connection
  • Wait a while and try again

We are processing you solution

Please press F5 if results are not displayed after a few seconds