Importing More Checks explainer

The aim of this puzzle: Use one of the imported “checking” functions as a callback

Walkthrough of the solution: The 1st line of code imports several functions. Importing is a way to include code that’s written somewhere else, in a different file. There are 4 “checking” functions that take a string and print out a message based on if the string includes a certain word. The checkPassport function looks for the word 'Passport'. The checkTicket function looks for the word 'Ticket'. And checkVehicle and checkHotel do a similar check.

In this puzzle, you need to change the callback function again. The callback is chosen where the updateAllAndCheck() is called. The 4th argument is the name of a function without parentheses. The checkPassport should be replaced with either checkTicket, checkVehicle, or checkHotel.

Sample code solution:
(Tap below to reveal)

import { updateAllNames, checkPassport, checkTicket, checkVehicle, checkHotel } from 'grasshopper.travel';

function updateAllAndCheck(string, oldPart, newPart, extraCheck) {
  extraCheck(string);
  return updateAllNames(string, oldPart, newPart);
}

console.log(travelDocument);
travelDocument = updateAllAndCheck(travelDocument, 'grasshoper', 'grasshopper', checkVehicle);
console.log(travelDocument);

JavaScript Concepts: Callback Functions, Calling Functions, Code Block (function), console.log(), import

CheckFunction & grasshopper. Travel, what are those? File name or what? In the same folder or from other folder?

Thanks

The things inside the curly brackets are functions or data that are exported from another file. The location of this file is specified using a string. If the file is in another folder, you’ll need to navigate to that folder inside your string, for example, '/anotherFolder/grasshopper.travel'. There’s more info here.

–Frankie

1 Like