Practice What You Learned

Create a JavaScript REPL from repl.it -- you can name it "JavaScript Functions Lab".`

Complete all work in your REPL.it

  • Write a function called minusOne that takes a parameter num. Assuming the argument is a number, print the argument -1.

    minusOne(10);        // 9
    minusOne(100);       // 99
    minusOne(Infinity);  // Infinity
  • Write a function makeSentence that takes three parameters and concatenates them into a fully formed sentence.

    makeSentence('I', 'want', 'chimichangas');

    => 'Oh boy, do I want chimichangas or what?'

  • Write a function called getLastElement that takes a parameter arr.
  • Invoke the function with an array as the argument.
  • The function should print the last element within the array.

    getLastElement([1, 2, 3, 4, 5, 6]);       // 6
    getLastElement(['a', 'b', 'c']);          // 'c'
    getLastElement([[1, 2, 3], [4, 5, 6]]);   // [4, 5, 6]

    Hint: arr[arr.length - 1] -->

Copyright © Per Scholas 2023