-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SRS updated Sesh 1 materials, added in our code-along examples
- Loading branch information
1 parent
e50b21a
commit 5072f7d
Showing
11 changed files
with
215 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 15 additions & 13 deletions
28
supplemental-react/01_ts_my_type_of_language/example_scripts/build/tsTests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
"use strict"; | ||
//BEHAVIOR YOU DON'T WANT | ||
//TYPES | ||
function divideTwoNums(a, b) { | ||
return a / b; | ||
} | ||
//console.log(divideTwoNums(8,4)); | ||
//console.log(divideTwoNums("tree","chocolate")); | ||
//CRASHING BEHAVIOR | ||
var myPet = "Rufus"; | ||
var newPet = { | ||
//console.log(divideTwoNums("apple","banana")); | ||
//INTERFACES | ||
var myPet = { | ||
name: { | ||
first: "Rufus", | ||
last: "the Third" | ||
last: "The Third" | ||
}, | ||
type: "dog" | ||
}; | ||
myPet = { | ||
name: { | ||
first: "Rufus", | ||
middle: "Or", | ||
last: "The Third" | ||
}, | ||
type: "dog" | ||
}; | ||
function callPet(pet) { | ||
return "Come here " + pet + "!"; | ||
return "Come here, " + pet.name.first; | ||
} | ||
console.log(callPet(myPet)); | ||
//transpiling | ||
var arr = [1, 2, 3, 4, 5]; | ||
var func = function (arr) { | ||
arr.forEach(function (num) { return console.log(num); }); | ||
}; | ||
//console.log(func(arr)); | ||
//console.log(callPet("Rufus")); |
24 changes: 24 additions & 0 deletions
24
supplemental-react/01_ts_my_type_of_language/example_scripts/build/typedExamples.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
//multiply two numbers | ||
function multiplyTwoNums(a, b) { | ||
return a * b; | ||
} | ||
var mattchoo = { | ||
name: "Matt", | ||
pronouns: "he/him", | ||
}; | ||
function greetPerson(person) { | ||
return "Hello there, " + person.name + " (" + person.pronouns + ")!"; | ||
} | ||
var smithsonian = { | ||
type: "obsidian", | ||
age: 40 | ||
}; | ||
var moma = { | ||
type: "diamond", | ||
age: 200 | ||
}; | ||
function sumAges(first, second) { | ||
return first.age + second.age; | ||
} | ||
//console.log(sumAges(smithsonian, moma)); |
37 changes: 37 additions & 0 deletions
37
supplemental-react/01_ts_my_type_of_language/example_scripts/examples.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//multiply two numbers | ||
function multiplyTwoNums(a,b){ | ||
return a*b; | ||
} | ||
|
||
|
||
|
||
//greetPerson | ||
|
||
const mattchoo = { | ||
name: "Matt", | ||
pronouns: "he/him", | ||
}; | ||
|
||
function greetPerson(person) { | ||
return "Hello there, " + person.name + " (" + person.pronouns + ")!"; | ||
} | ||
|
||
//console.log(greetPerson(mattchoo)); | ||
|
||
//Add Ages of two rocks | ||
|
||
const smithsonian = { | ||
type: "obsidian", | ||
age: 40 | ||
} | ||
|
||
const moma = { | ||
type: "diamond", | ||
age: 200 | ||
} | ||
|
||
function sumAges(first, second){ | ||
return first.age + second.age; | ||
} | ||
|
||
//console.log(sumAges(smithsonian, moma)); |
52 changes: 33 additions & 19 deletions
52
supplemental-react/01_ts_my_type_of_language/example_scripts/jsTests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
//BEHAVIOR YOU DON'T WANT | ||
// function divideTwoNums(a,b){ | ||
// return a/b; | ||
// } | ||
|
||
//divide two nums | ||
function divideTwoNums(a,b){ | ||
return a/b; | ||
} | ||
// console.log(divideTwoNums(8,4)); | ||
|
||
// console.log(divideTwoNums("tree","chocolate")); | ||
|
||
|
||
//TODO: show refactoring functions and interfacing with objects | ||
//console.log(divideTwoNums("apple","banana")); | ||
|
||
|
||
//CRASHING BEHAVIOR | ||
const myPet = "Rufus"; | ||
|
||
const newPet = { | ||
//Call Your Pet | ||
let myPet = "Rufus"; | ||
myPet = { | ||
name: { | ||
first: "Rufus", | ||
last: "the Third" | ||
last: "The Third" | ||
}, | ||
type: "dog" | ||
}; | ||
} | ||
|
||
|
||
function callPet(pet){ | ||
return "Come here "+ pet.name.first + "!"; | ||
return "Come here, " + pet; | ||
} | ||
|
||
console.log(callPet(myPet)); | ||
|
||
//error! | ||
console.log(callPet(newPet)); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
"license": "MIT", | ||
"dependencies": { | ||
"typescript": "^4.3.4" | ||
} | ||
}, | ||
"scripts": {} | ||
} |
16 changes: 0 additions & 16 deletions
16
supplemental-react/01_ts_my_type_of_language/example_scripts/tsTests.js
This file was deleted.
Oops, something went wrong.
64 changes: 28 additions & 36 deletions
64
supplemental-react/01_ts_my_type_of_language/example_scripts/tsTests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,46 @@ | ||
|
||
//BEHAVIOR YOU DON'T WANT | ||
function divideTwoNums(a: number, b: number): number{ | ||
//TYPES | ||
function divideTwoNums(a : number ,b : number) : number{ | ||
return a/b; | ||
} | ||
|
||
//console.log(divideTwoNums(8,4)); | ||
|
||
//console.log(divideTwoNums("tree","chocolate")); | ||
|
||
//CRASHING BEHAVIOR | ||
// const myPet = "Rufus"; | ||
// type Pet = string; | ||
// // function callPet(pet : Pet) : string{ | ||
// // return "Come here " + pet + "!" | ||
// // } | ||
|
||
// const newPet = { | ||
// name: { | ||
// first: "Rufus", | ||
// last: "the Third" | ||
// }, | ||
// type: "dog" | ||
// } | ||
|
||
//console.log(divideTwoNums("apple","banana")); | ||
|
||
|
||
//INTERFACES | ||
|
||
interface Pet { | ||
let myPet : Pet = { | ||
name: { | ||
first: string, | ||
last: string | ||
first: "Rufus", | ||
last: "The Third" | ||
}, | ||
type: string | ||
type: "dog" | ||
} | ||
|
||
function callPet(pet : Pet) : string{ | ||
return "Come here " + pet.name.first + "!" | ||
myPet = { | ||
name: { | ||
first: "Rufus", | ||
middle: "Or", | ||
last: "The Third" | ||
}, | ||
type: "dog" | ||
} | ||
|
||
//this gives us errors! | ||
//console.log(callPet(myPet)); | ||
//console.log(callPet(newPet)); | ||
|
||
interface Pet { | ||
name: { | ||
first: string; | ||
middle?: string; | ||
last: string; | ||
}, | ||
type : string | ||
} | ||
|
||
|
||
function callPet(pet : Pet){ | ||
return "Come here, " + pet.name.first; | ||
} | ||
|
||
console.log(callPet(myPet)); | ||
|
||
//transpiling | ||
// const arr = [1,2,3,4,5] | ||
// let func = (arr: Array<number> ) =>{ | ||
// arr.forEach(num=>console.log(num)) | ||
// } | ||
//console.log(func(arr)); | ||
//console.log(callPet("Rufus")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.