JavaScript Fundamentals -- Functions in JavaScript

Functions in JavaScript Exercise 1 Review


Here's one way you could have finished this exercise. These are just examples; your solutions may look a little different.

// 1. Write a named function that logs the "name" parameter to the console
function sayHello(name) {
  console.log('Hello ', name);

// 2. Write an arrow function that adds two numbers together using implicit return. Print the result to the console.
const add = (num1, num2) => num1 + num2;
const sum = add(4, 4);

// 3. Write an arrow function that subtracts two numbers, not using implicit return. Print the result to the console.
const subtract = (num1, num2) => {
  return num1 - num2;
const difference = subtract(10, 5);

// 4. Add a named function to the pizza object called "cook". Print a message to the console saying how long it will take to cook
const pizza = {
  name: 'Pepperoni',
function cook() {
  console.log( + ' will take 10 minutes to cook');

// 5. Add an arrow function to the dog object that logs "bark, bark" to the console when called.
const dog = {
  name: 'Duke',
  bark: () => {
    console.log('bark, bark');

// 6. Add an anonymous function to the ice cream object called "eat" that logs a message saying the ice cream is being eaten
const iceCream = {
  name: 'vanilla',
  eat: function() {
    console.log( + ' is being eaten');

You can see the answers to this exercise in this StackBlitz Project.


I finished! On to the next chapter