Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Update JS-Core lesson 2 research (#64)
Browse files Browse the repository at this point in the history
* moving coding intro into coding-101 #10 

* js-core lesson 1 updated based on Node Girls workshop #6
The Node Girls workshop is a great immersive start to JS: I've amended some bits to use more accurate terminology, I also updated some of the code samples to be more relevant to our students. I changed the Array explanation to use Tim's explanation as it is easier to grasp. I've also moved the existing content of Lesson 1 to Lesson 2 as it will serve as a good way to reiterate the more complex concepts like arrays, objects etc...

* moving arrays and object from lesson 1 to lesson 2

* update JS-Core lesson 2

* updating research section for JS-Core lesson 2

* putting skeleton for lesson 3
  • Loading branch information
kabaros authored May 26, 2017
1 parent fb9cb16 commit ab2112c
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 73 deletions.
27 changes: 23 additions & 4 deletions js-core/lesson2.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,30 @@ countries.push('United States of America', 'France');

4. **Research:**

In the next class, we expect to do a short presentation about one of these topics:
Read the chapter from JS: The Good parts
- Chapter 9: Style - it's a short chapter, everyone start by reading that chapter.
- ALL: Read the chapter about **Objects** (up to Reference)
- Read the chapter about **Arrays** (ignore the Methods section)
- Read the chapter about Functions up to the section about **Return**

When reading always try the code snippets by yourself in Node. (change document.writeln to console.log)

Next class - we want you to do a presentation (including showing some code sample) for one of these concepts:

- Switch Statements and Ternary Operators
- Math methods in JavaScript
- While loops (compare them to for Loops)
- Array.slice and Array.splice
- Array.map and Array.forEach
- Array.find and Array.filter
- String.replace, String.search and other String methods
- Object.keys (How to loop the properties of an object)
- [Function arguments](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/arguments)
- [Advanced] [Different ways of Creating objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Creating_new_objects)
- [Advanced] [Inheritance](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Inheritance)
- [Advanced] [Regular Expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)

- Conditionals other than If/Else: Switch Statements, Ternary Operators
- Loops other than For: While loops
- Read the [documentation about Strings](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Methods) and show us code that implements two of the methods described.

## Prepare for the next class
1. Look over these examples for interacting with the DOM using JavaScript. We'll discuss these in more detail next week, but try to make an idea of the different API methods and what they do. [DOM Examples](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples)
2. Reserach **Unit Testing** (next time, know how to answer the question: **what is TDD?**)
82 changes: 13 additions & 69 deletions js-core/lesson3.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,25 @@
# JavaScript Core 2
# JavaScript Core 3
** What we will learn today?**
- JavaScript in the browser
- Unit Testing
- TDD
- Intro to JavaScript in the browser
- DOM
- DOM Events
- AJAX / API (REST)
- Callbacks and Promises
- JSON
- Callbacks

- More Arrays and loops
- Functional utils (map, foreach, filter)

- Async - settimeout

---

# Callbacks

You probably noticed in last few exercises that JavaScript functions can be passed as arguments to other functions.

Callbacks are JavaScript functions that are passed as arguments to other functions
so they can be executed inside those functions once they're finished.

Example:

```javascript

function a(callback) {
var x = 1000;
if(callback) {
callback();
}
return x;
}

```

> **Exercise**:
> - Look up the global `setTimeout` function
> - Write a function that takes a string as a parameter, waits 2 seconds, and then logs out the string

## More arrays and loops + tests

Before we dive into the exercises, a word on testing:
- All of us write buggy code. Thinking about what inputs our software is supposed to handle
and writing tests to verify that it behaves as expected for those inputs helps us
prevent most of those bugs.
- By writing good tests for our pieces of functionality helps ensure that no one else can
break it by mistake in the future
- Sometimes, just by thinking about what tests to write might bring up big flaws in our
initial logic

Testing example; consider the following code:

```javascript
function containsBob(a) {
return a.includes("bob");
}
```

How might we test the above? Some example inputs we can test with:

```javascript
containsBob("aabobaa"); // expected: true, actual: true
containsBob("hello"); // expected: false, actual: false
containsBob("bob"); // expected: true, actual: true
containsBob("b ob"); // expected: false, actual: false
containsBob(""); // expected: false, actual: false

containsBob(1); // expected: false, actual: TypeError
```
# Unit Testing
We go through the problems they've already solved in the last week, refactor and do them in a testable way - introduce TDD etc..

> **Exercise**:
> Open [this CodePen](http://codepen.io/rarmatei/pen/EWJjrZ?editors=0012) and follow the instructions there
Why is testing important?
Different levels of testing?
Regression?

maybe we start with not using a framework at all?
We use `JEST` after

# JS in the browser
https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples


## Topic 1
Expand Down
68 changes: 68 additions & 0 deletions js-core/lesson4.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# JavaScript Core 4
** What we will learn today?**
- A taster of Functional Programming
- AJAX / API (REST)
- Callbacks and Promises
- JSON
- Callbacks

- More Arrays and loops
- Functional utils (map, foreach, filter)

- Async - settimeout

?? maybe Object Oriented JS (prototypes and such),
call, apply etc.. or more algorithmic techniques (recursion etc..)
Expand Down Expand Up @@ -196,6 +204,66 @@ console.log(object.greeting); // "how are you?"
```


# Callbacks

You probably noticed in last few exercises that JavaScript functions can be passed as arguments to other functions.

Callbacks are JavaScript functions that are passed as arguments to other functions
so they can be executed inside those functions once they're finished.

Example:

```javascript

function a(callback) {
var x = 1000;
if(callback) {
callback();
}
return x;
}

```

> **Exercise**:
> - Look up the global `setTimeout` function
> - Write a function that takes a string as a parameter, waits 2 seconds, and then logs out the string

## More arrays and loops + tests

Before we dive into the exercises, a word on testing:
- All of us write buggy code. Thinking about what inputs our software is supposed to handle
and writing tests to verify that it behaves as expected for those inputs helps us
prevent most of those bugs.
- By writing good tests for our pieces of functionality helps ensure that no one else can
break it by mistake in the future
- Sometimes, just by thinking about what tests to write might bring up big flaws in our
initial logic

Testing example; consider the following code:

```javascript
function containsBob(a) {
return a.includes("bob");
}
```

How might we test the above? Some example inputs we can test with:

```javascript
containsBob("aabobaa"); // expected: true, actual: true
containsBob("hello"); // expected: false, actual: false
containsBob("bob"); // expected: true, actual: true
containsBob("b ob"); // expected: false, actual: false
containsBob(""); // expected: false, actual: false

containsBob(1); // expected: false, actual: TypeError
```

> **Exercise**:
> Open [this CodePen](http://codepen.io/rarmatei/pen/EWJjrZ?editors=0012) and follow the instructions there

# Resources
1. [Pass by value/reference](http://docstore.mik.ua/orelly/webprog/jscript/ch11_02.htm)
Expand Down

0 comments on commit ab2112c

Please sign in to comment.