ALAB 308H.5.1 - JavaScript Functions
Learning Objectives
In this lab, you'll be completing some challenges using JavaScript functions to test and reinforce your ability to:
- Demonstrate the difference between function declarations and function expressions.
 - Create functions that solve a specific task.
 
CodeSandbox
This lab uses CodeSandbox as one of its tools.
If you are unfamiliar with CodeSandbox, or need a refresher, please visit our reference page on CodeSandbox for instructions on:
- Creating an Account
 - Making a Sandbox
 - Navigating your Sandbox
 - Submitting a link to your Sandbox to Canvas
 
Instructions
- Create a 
VanillaCodeSandbox and name it "JavaScript Functions Lab." - Define and code 6 of the 10 functions below in the 
index.jsfile. - Define the functions using the approach as specified (either as a function expression or declaration).
 - Be sure to number each function with a comment above it cooresponding to the numbers below.
 - After each function, call it at least once and 
console.logthe results. - Submit the link to your CodeSandbox on Canvas when you are finished.
 
For example, here's the first function, our gift to you:
// 1.
function maxOfTwoNumbers(x, y) {
  if (x >= y) {
    return x;
  } else {
    return y;
  }
  // or more "elegantly" using the fantastic ternary expression!
  // return  x >= y ? x : y;
}
console.log(maxOfTwoNumbers(3, 9));
// 2.
...Deliverables
- A link to a CodeSandbox that contains at least six completed functions from the following problem statements, along with 
console.logstatements that test their results. 
Problem Statements
Here are the functions:
- (completed above) Define a function, as a function declaration, 
maxOfTwoNumbersthat takes two numbers as arguments and returns the largest of them. If they are the same, return that number. Use theif...elseconstruct or a ternary expression - theMath.maxmethod is not allowed. - Define a function, as a function expression, 
maxOfThreethat takes three numbers as arguments and returns the largest of them. Again, theMath.maxmethod is not allowed. - Define a function, as a function declaration, 
isCharAVowelthat takes a character as an argument and returnstrueif it is a vowel,falseotherwise. - Define a function, as a function expression, 
sumArraythat takes an array of numbers and returns the sum of those numbers. For example,sumArray([2, 4, 5]);would return11. - Define a function, as a function declaration, 
multiplyArraythat takes an array of numbers and returns the product of those numbers. For example,multiplyArray([2, 4, 5]);would return40. - Define a function, as a function expression, 
numArgsthat returns the number of arguments passed to the function when called. - Define a function, as a function declaration, 
reverseStringthat takes a string, reverses the characters, and returns it. For example,reverseString('rockstar');would return the string "ratskcor". - Define a function, as a function expression, 
longestStringInArraythat takes an array of strings as an argument and returns the length of the longest string. - Define a function, as a function declaration, 
stringsLongerThanthat takes an array of strings and a number as arguments; and returns an array of the strings that are longer than the number passed in. For example,stringsLongerThan(['say', 'hello', 'in', 'the', 'morning'], 3);would return["hello", "morning"]. - Define a function, as a function expression, 
addListthat accepts any quantity of numbers as arguments, adds them together, and returns the resulting sum. Assume all parameters will be numbers. If called with no arguments, return0(zero). 
Bonus
If you have time, feel free to complete more than 6 of the above 10 functions. More practice is always better!
