RDU
© 2016 Thinkful RDU All Rights Reserved.
Ben White
Left an anthropology PhD program after four years
Worked as a developer first in 2010 at a marketing software company doing sentiment analytics
Joined Thinkful in 2013 as an education engineer, and now run curriculum development
© 2016 Thinkful RDU All Rights Reserved.
First steps towards becoming a software engineer
Communicate better with developers
Build out your business and app ideas
© 2016 Thinkful RDU All Rights Reserved.
Details at http://githut.info
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
A variable is a name that points to a value.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
Declaring vs. assigning vs. declaring and assigning
// declaring
var firstVariable;
// assigning a value
firstVariable = 6;
// re-assigning value
firstVariable += 1;
// referring to variable
console.log(firstVariable);
alert(firstVariable);
// declaring and assigning
var secondVariable = 'foo';
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
var foo = 'foo';
var bar = "bar";
var fooBar = foo + bar;
© 2016 Thinkful RDU All Rights Reserved.
var width = 10;
var height = 5.5;
console.log("Area is " + (width * height)); // => Area is 55
© 2016 Thinkful RDU All Rights Reserved.
// booleans and logical operators
var sunny = true;
var warm = false;
var shouldGoOut = sunny && warm;
// null
var accountNum = null;
// undefined
var myVar;
console.log(myVar);
© 2016 Thinkful RDU All Rights Reserved.
Used to represent re-usable sets of instructions
// defining
function sayHi() {
console.log('Hi');
}
// executing
sayHi(); // => Hi
// this function takes a `name` argument
function sayHiToName(name) {
console.log('Hi ' + name);
}
sayHiToName('Sheila') // => Hi Sheila
// this function *returns* a value
function isEven(num) {
return num % 2 === 0;
}
isEven(3); // => false
© 2016 Thinkful RDU All Rights Reserved.
Hold collections of values together
// defining object
var fido = {
type: 'dog',
legs: 4,
name: 'Fido',
speak: function() { console.log('arf arf') }
};
// dot notation
console.log(fido.name) // => Fido
fido.speak(); // => arf arf
// reassigning the value of .legs
fido.legs = 3;
// bracket notation
fido['type']; // => dog
// arrays
var myList = [1, 2, "three", true, fido];
myList[0]; // => 0
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
// inside app.js
function sayMyName() {
console.log('Ben');
}
sayMyName();
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
// inside app.js
// ... existing code
function adder(num1, num2) {
return num1 + num2;
}
console.log(adder(3, 5));
© 2016 Thinkful RDU All Rights Reserved.
Built in string methods
var foo = "foo bar foo bar foo bar";
foo.length; // =>
foo.charAt(0); // => "f"
foo.indexOf("bar"); // => 4
foo.slice(1); // => "oo bar foo bar foo bar"
foo.split(" ") // => ["foo", "bar", "foo", "bar", "foo", "bar"]
foo.toUppercase() // => "FOO BAR FOO BAR FOO BAR"
foo.replace('foo', 'bar') // => 'bar bar bar bar bar bar'
© 2016 Thinkful RDU All Rights Reserved.
Special characters and escaping
var foo = "He said, \"Foo!\"";
var bar = 'Dear Paul,\nHow are you?';
© 2016 Thinkful RDU All Rights Reserved.
© 2016 Thinkful RDU All Rights Reserved.
function wisePerson(who, what) {
console.log(
"A wise person named " + who + " said, '" +
what + "'");
}
wisePerson('Paul', "Carpe diem!");
© 2016 Thinkful RDU All Rights Reserved.
console.log(shouter(
"I am whispering can't you tell?")); // => I AM WHISPERING CAN'T YOU TELL?
© 2016 Thinkful RDU All Rights Reserved.
function shouter(text) {
return text.toUpperCase();
}
console.log(shouter('I am whispering'));
© 2016 Thinkful RDU All Rights Reserved.
{
text: "All your base belong to us",
author: "haxor3000",
wordLength: 5,
isRetweet: false,
mentionsOthers: false
}
© 2016 Thinkful RDU All Rights Reserved.
Given:
{
text: "All your base belong to us",
author: "haxor3000",
wordLength: 5,
mentionsOthers: false
}
var tweet = {
author: "@billy",
text: "All your base belong to us"
id: 333333
}
`analyzeTweet(tweet)` should return:
© 2016 Thinkful RDU All Rights Reserved.
Given:
{
text: "RT @billy all your base belong to us",
author: "@sally",
wordLength: 8,
mentionsOthers: true
}
var tweet = {
author: "@sally",
text: "RT @billy All your base belong to us"
id: 444
}
`analyzeTweet(tweet)` should return:
© 2016 Thinkful RDU All Rights Reserved.
Hints
// convert string into array of words
var foo = ['lions and tigers and bears oh my!']
var splitUp = foo.split(" ");
console.log(splitUp); // => [
'lions', 'and', 'tigers', 'and', 'bears', 'oh', 'my'];
// get length of array
var myArray = [1, 2, 3];
console.log(myArray.length); // => 3
// check if string contains substring
var string = "cats and dogs"
var containsCats = string.indexOf("cats") > -1;
© 2016 Thinkful RDU All Rights Reserved.
function analyzeTweet(tweet) {
return {
text: tweet.text,
numberWords: tweet.split(" ").length,
mentionsOthers: tweet.indexOf('@') > -1
};
}
analyzeTweet({
text: 'lions and tigers and bears',
author: '@janeDoe',
id: 2020202020
});
© 2016 Thinkful RDU All Rights Reserved.
Email me with questions or suggestions:
ben@thinkful.com
RDU