Final Code, Variable Scope Notes & Results

Here’s my code. This is my first time programming anything, and so far its a blast. The only problem I had, where I needed to ask help from a friend, was the variable scopes, and how it’s passing along the value. I understand it now, but here’s what confused me.

The instructor, Gavin is great by the way, thank you. The only thing that wasn’t clear, and confusing…was when he named the variable Difficulty in both the PlayGame function and the PrintIntroduction function. Which made me think that both Difficulty variables in those functions were one and the same…but they’re not. So, for a while I thought that somehow both functions used the exact same variable outside their functions, but that’s not possible, but that’s what i thought so I was going in circles.

So, in my code, I labeled it DifficultyA in my PlayGame and DifficultyB in my PrintIntroduction. That way…visually, I can see that there are different variables, and it was those variables that was carrying the value of LevelDifficulty. That’s was my only set back, but I understand it now.

And as for my game, I couldn’t get past level 5. I had the numbers that equaled the product, but not add to the sum! I take this as a win because I created a game where the challenge was real!

Also, another way to add difficulty to the Code Variable that I experimented with, is this:
image

1 Like

Awesome post!

Privacy & Terms