Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content covering scopes topic #68

Merged
merged 26 commits into from
Mar 16, 2020
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ddaaffb
Create Scopes challenge section
bonham000 Mar 2, 2020
77c599f
Merge branch 'master' into content/scopes
bonham000 Mar 2, 2020
e7e8f12
Merge branch 'master' into content/scopes
bonham000 Mar 2, 2020
c7a414e
Merge branch 'master' into content/scopes
bonham000 Mar 9, 2020
6095fb1
Update Slack admin alert message
bonham000 Mar 9, 2020
af43ef2
Add logo in README
bonham000 Mar 9, 2020
ee91b62
Post to Slack when a user purchases a course
bonham000 Mar 9, 2020
f54aed1
Merge branch 'master' into content/scopes
bonham000 Mar 9, 2020
2ae1346
Merge branch 'master' into content/scopes
bonham000 Mar 11, 2020
1a994d8
Fix cool bug in partitionChallengesBySection !!!
bonham000 Mar 11, 2020
31c0178
Update test utils and starter test code, finish Global Scope challenge
bonham000 Mar 11, 2020
724510c
Add Math object global scope challenge
bonham000 Mar 11, 2020
91ba103
Update test starter code
bonham000 Mar 11, 2020
b9d73e4
Update test snapshot
bonham000 Mar 12, 2020
bf0ca4c
Merge branch 'master' into content/scopes
bonham000 Mar 12, 2020
7750b4b
Merge branch 'master' into content/scopes
bonham000 Mar 15, 2020
4cd3d78
Update and add Math challenges
bonham000 Mar 15, 2020
da152ae
Add global Date object challenge
bonham000 Mar 15, 2020
1f25a26
Add Date challenge on unix time
bonham000 Mar 15, 2020
2893f69
Create local scope challenge
bonham000 Mar 15, 2020
ca1ddad
Add function local scope challenge
bonham000 Mar 15, 2020
2c6cd5d
Add content for functions local scope challenge
bonham000 Mar 15, 2020
db9bc96
Add final note on scope challenge
bonham000 Mar 15, 2020
d543f7a
Merge branch 'master' into content/scopes
bonham000 Mar 15, 2020
ef35cc0
Change test editor language to typescript
bonham000 Mar 16, 2020
7bbe8f2
Merge branch 'master' into content/scopes
bonham000 Mar 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add final note on scope challenge
  • Loading branch information
bonham000 committed Mar 15, 2020
commit db9bc965b8c5fff4163cb23edcb9a24338d634b1
11 changes: 11 additions & 0 deletions packages/common/src/courses/01_programming_fundamental.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,17 @@
"solutionCode": "const outerValue = \"Hello, from the outer side!\";\n\n// The function creates it's only private scope\nconst aPrivateFunctionSpace = () => {\n // Change the code here!\n const outerValue = \"Hello, from the inner side!\";\n return outerValue;\n}\n\nconst innerValue = aPrivateFunctionSpace();\n\n// Log the results\nconsole.log(`innerValue: ${innerValue}`);\nconsole.log(`outerValue: ${outerValue}`);",
"content": "Just like `{...}` brackets, functions can be nested. You can create functions within functions, or brackets within functions, or vice versus. All of these create new unique scopes. And they can be very nested\\! For instance, consider the following code:\n\n```typescript\nconst aVeryScopedWorld = () => {\n // The main function scope\n\n {\n // Some brackets scope\n const anotherFunction = () => {\n // Now we are inside a new function and new scope\n for (let i = 0; i < 10; i++) {\n // A new scope, yet again!\n\n const theForLoopFunction = () => {\n // A function defined inside the for loop!\n // Yes, it also creates a new scope!\n return i;\n }\n\n const result = theForLoopFunction();\n console.log(result);\n }\n }\n }\n}\n\n```\n\nOk, this is a bit overkill\\! But it should get the idea across. Each of these new functions or brackets creates a new local scope\\!\n\nAlso, it's worth pointing out how flexible TypeScript is here. You can create and nest different constructs like this in very flexible ways. This gives you a lot of options as you craft programs to perform tasks and also as you think about the design, organization, and architecture of your programs.\n\nFor instance, should you create that new function right here, in the body of another function, or should you write outside in order to better separate your code?"
},
{
"id": "Mpgh4e9m",
"type": "media",
"title": "A Final Note on Scope",
"instructions": "",
"testCode": "// Write your tests here:\ntest(\"Write your test assertion here\", () => {\n expect(true).toBe(true);\n});\n",
"videoUrl": "",
"starterCode": "",
"solutionCode": "",
"content": "So far we have seen some simple examples of what scope is in a computer program and how it is defined by functions and block statements of code.\n\nOne of the main ways scope is useful is by giving you the ability to create separations between pieces of code. This helps to improve the organization and readability of your program, and it may prevent bugs and problems as well.\n\nHowever, scope is not the only tool a programmer has to accomplish a goal like this.\n\nLater on, you will learn how to write programs and build apps using a real code environment \\(not this fun editor playground in a browser\\!\\). When you reach that stage, you will have a lot of other tools at your disposal.\n\nFor example, you can define parts of your program in different files, put related files in different folders, and then _import_ values from one file into another. You can also control what you _import_ and _export_. This is a very powerful capability for organizing software programs. These same skills will also allow you to download open source code other people have written and import this code in your own projects as well\\! This is incredibly useful and opens the doors to building a number of interesting applications\\!\n\nYou will learn the details of this later, but for now just keep it in mind as a short preview and extension of the ideas of scopes which will come in handy later\\!\n\nTake a look at this code snippet for a short teaser:\n\n```typescript\n// This imports the library \"request\", which is open source and written\n// and maintained by other developers.\nimport request from \"request\";\n\n// The request library lets you make HTTP requests to URLs!\nrequest(\"http://www.google.com\", (error, response, body) => {\n if (error) {\n throw error;\n } else {\n console.log(\"Success!, Response received: \", body);\n // Do somethine else here...\n }\n});\n\n```\n"
},
{
"id": "9wRw1y5V",
"type": "section",
Expand Down