This course has been updated! We now recommend you take the JavaScript: The Recent Parts course.

Check out a free preview of the full ES6: The Right Parts course:
The "Exercise 1: Variable Scoping" Lesson is part of the full, ES6: The Right Parts course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will modify the for loop in the ex1.js file add functions to the fns array. These functions will use the let and const keywords to ensure the correct closures are created and the assertion at the bottom of the file remains true.

Get Unlimited Access Now

Transcript from the "Exercise 1: Variable Scoping" Lesson

[00:00:00]
>> [MUSIC]

[00:00:03]
>> Kyle Simpson: Let's open up exercise one. You'll notice that I've created some functions here, and I've created some for loops and stuff. And here's our test case at the bottom. It needs to assert true, which is the case that the x value of 2 multiplied by 2. So we're saying that 4 needs to be the same thing that's returned if I call the function in this fns array at position 4.

[00:00:29] So in other words, I'm gonna loop over from 0 up to 5, not including, and I'm gonna add functions to an fns array. Each one of those functions needs to close over some variable such that when the function is called, it returns that value, okay? So looking at your IIFE here, looking at your var statements, figure out which ones of these should be made into lets and conts.

[00:00:55] And re-factor this code and set yourself up correctly with your closure. Should only take a few lines of code. So we'll just take a three-minute break, and then we'll talk about the solution.