Globals 4 exercises
Problem

Add Functionality to Existing Global Interfaces

In this exercise, we're going to modify something on the window interface.

Here we have a window.makeGreeting function:


window.makeGreeting = () => "Hello!";

The function currently returns "Hello!", but it needs to be updated to return any string.

As seen in the tests,

Loading exercise

Transcript

0:00 In this exercise, we're going to modify something on the window interface. We've got this window.makeGreeting is this function that returns hello. We just want it to basically represent type of window.makeGreeting. It should be just a function that returns a string. That's what we want.

0:18 We don't want it to be available on the global this. We just want it to be available on the window. How on earth do we type this? We're going to need declare global again. Then you're going to somehow need to modify the upper-case window interface to add a makeGreeting function.

0:37 You'll need to know some concepts of this. The first one is going to be declaration merging, which is something we haven't covered yet. There are some docs on it. I'll provide a link in the section resources. You might be able to just figure it out on your own because I've given you enough breadcrumbs here I think.

0:56 This looks complicated. Make sure that you're targeting the right interface using declare global. Good luck.