Assignment not working?

Tell us what’s happening:
I changed the ‘var’ keyword to ‘let’ to limit the scope, which I thought was the only goal of the assignment but it doesn’t seem to be enough. Even the solution presented when you ask for a hint just has the code I have as written. However, it doesn’t work and doesn’t allow me to proceed - unless I change the if statement to false which then gets rid of the block scope statement entirely and allows me to proceed, but is not what the assignment is supposed to be I don’t believe?

Your code so far


function checkScope() {
'use strict';
let i = 'function scope';
if (true) {
  i = 'block scope';
  console.log('Block scope i is: ', i);
}
console.log('Function scope i is: ', i);
return i;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0.

Challenge: Compare Scopes of the var and let Keywords

Link to the challenge:

You need to declare the i inside the if block. Remember that if you assign a variable without declaring it, it will be declared in the global scope.

1 Like

ah, thanks I wasn’t seeing the one in the if statement