In and Out explainer


#1

The aim of this puzzle: Complete the price function so that it returns the .price property of the item.

Walkthrough of the solution: An arrow function can work like a normal function, with input parameters and a return value. Inside the parentheses (), you add the names of the parameters that the function will use. The priceOf function should take an item and then return its price, so it has 1 parameter which we can call item.

To make the function output the price, we need to add the return keyword between the curly brackets {}. The value that should be returned is the .price property of the item. That looks like return item.price

Sample code solution:
(Tap below to reveal)

import { groceries } from 'grasshopper.store';

let nameOf = (item) => {
  return item.name;
};
let priceOf = (item) => {
  return item.price;
};

console.log(nameOf(groceries[0]));
console.log(priceOf(groceries[0]));

JavaScript Concepts: Array Indexing, Code Block (arrow function), console.log()

Summary

This text will be hidden


#3