In this lab, we will review two key topics covered so far: Objects and Functions. These are two vital topics for understanding JavaScript fundamentals, and will be used heavily as we build web apps in later units.
Write a function that takes in two numbers as input and returns their average
Input: 4,6
Output: 5
Write a function that takes in three numbers as input and returns their average
Input: 1,3,5
Output: 3
Write a function that takes in an array of numbers as input and returns their average
Input: [1,2,3,4,5,10,10]
Output: 5
Write a function that returns a new array with all even numbers removed.
Input: [1,2,3,4,5,6]
Output: [1,3,5]
BONUS: If you didn't, rewrite this using an array method with a callback
Write a function that checks to see whether every number in an array is positive.
Input: [-4,3,-2,4]
Output: false
BONUS: If you didn't, rewrite this using an array method with a callback
Write a function that lowercases all strings in an array of strings.
Input: ["HELLO", "THERE", "THESE", "ARE", "SOME", "STRINGS"]
Output: ["hello", "there", "these", "are", "some", "strings"]
BONUS:
-
A. If you didn't, rewrite this using an array method with a callback
-
B. Make it work even if the array has mixed types inside so that input =
[1, 'HELLO', {one: 'uno'}]
would give output =['hello']
Write a function that combines an array of strings into a single string separated by spaces.
Input: ["It’s", "not", "a", "bug.", "It’s", "an", "undocumented", "feature!"]
Output: "It’s not a bug. It’s an undocumented feature!""
Write a function that returns a random integer between 1 and n
Input: 7
Output: 3
Bonus: Your function should return 1 or 7 inclusive
Write a function that returns the sum of the absolute values of an array
Input: [3,-4,5,-6]
Output: 18
Write a function that converts a temperature in Fahrenheit to Celsius
Input: 212
Output: 100
-
Write an object that represents a User. It should have a property for the user's name, email address, and age.
-
Make 3 different user objects and store them in an array
-
Write a function that takes in an array of User objects, and returns an array with only their email addresses
-
Write a function that takes in an array of User objects, and returns the average age of all users. Rounded down.
-
Write a function that takes in an array of User objects and returns whether or not all users have an age greater than 18
-
Write an object that represents a Recipe. It should have a property for the recipe's ingredients, name, and how long it will take to make.
-
Make 3 different recipe objects and store them in an array.
-
Write a function that takes in an array of Recipe objects and returns the recipe that will take the least amount of time to make.
-
Write a function that takes in an array of Recipe objects and returns an array containing all the ingredients you need to make all of the recipes.
Bonus: Remove duplicate ingredients from the final array
- Write a function that takes in an array of Recipe objects and an array of ingredients and returns all the recipes that you are able to make.