+ All Categories
Home > Technology > An Introduction to JavaScript: Week One

An Introduction to JavaScript: Week One

Date post: 01-Nov-2014
Category:
Upload: event-handler
View: 366 times
Download: 0 times
Share this document with a friend
Description:
 
Popular Tags:
70
Introduction to JavaScript #1 @danielknell
Transcript
Page 1: An Introduction to JavaScript: Week One

Introduction to JavaScript #1

@danielknell

Page 2: An Introduction to JavaScript: Week One

Basics

Page 3: An Introduction to JavaScript: Week One

Basics

•Expressions

•Conditionals

•Loops

Page 4: An Introduction to JavaScript: Week One

Expressions

Page 5: An Introduction to JavaScript: Week One

Expressions•Math and Numbers

•Strings and Concatenation

•Special

•Booleans and Comparison

•Functions

•Objects and Arrays

Page 6: An Introduction to JavaScript: Week One

http://artsn.co/js-repl

Page 7: An Introduction to JavaScript: Week One

Numbers and Math

Page 8: An Introduction to JavaScript: Week One

42

Page 9: An Introduction to JavaScript: Week One

42.5

Page 10: An Introduction to JavaScript: Week One

× ÷ + −

Page 11: An Introduction to JavaScript: Week One

Math 4 * 2;4 / 2;4 + 2;4 - 2;100 % 3;99 + (9 / 9);-3;-(3+1);

Page 12: An Introduction to JavaScript: Week One

Mathmagical

Page 13: An Introduction to JavaScript: Week One

Take a 4 digit number

e.g. 1234

Page 14: An Introduction to JavaScript: Week One

Shuffle the digitse.g. 2413

Page 15: An Introduction to JavaScript: Week One

Subtract the smaller from the larger

e.g. 2413 - 1234

Page 16: An Introduction to JavaScript: Week One

Sum the digits of the result

e.g. 566 → 5 + 6 + 6 → 1 + 7 → 8

Page 17: An Introduction to JavaScript: Week One

Sum the digits of the resulte.g. 566 % 8

Page 18: An Introduction to JavaScript: Week One

0

Page 19: An Introduction to JavaScript: Week One

Variables

Page 20: An Introduction to JavaScript: Week One

Variables var x = 5;var y = 99 + (9 / 9);var z = x * y;

Page 21: An Introduction to JavaScript: Week One

More Math var x = 5;x++;x--;

Page 22: An Introduction to JavaScript: Week One

Strings and Concatenation

Page 23: An Introduction to JavaScript: Week One

Strings "hello";'world';"hello" + "world";

Page 24: An Introduction to JavaScript: Week One

Strings "five plus two equals: " + (5 + 2);

Page 25: An Introduction to JavaScript: Week One

Strings var who = 'world';var greeting = "hello" + who;

greeting[0]

Page 26: An Introduction to JavaScript: Week One

Special

Page 27: An Introduction to JavaScript: Week One

null

Page 28: An Introduction to JavaScript: Week One

nullvar x = null;

Page 29: An Introduction to JavaScript: Week One

undefined

Page 30: An Introduction to JavaScript: Week One

undefinedvar x;

Page 31: An Introduction to JavaScript: Week One

Boolean and Comparison

Page 32: An Introduction to JavaScript: Week One

True / False

Page 33: An Introduction to JavaScript: Week One

False-ish0""nullundefined

Page 34: An Introduction to JavaScript: Week One

Boolean Mathtrue && true;false || true;!false;

Page 35: An Introduction to JavaScript: Week One

Comparison1 == "1";1 != "2";2 > "1";1 < "2";2 >= "1";1 <= "2";

1 === 1;1 !== "1";

Page 36: An Introduction to JavaScript: Week One

Functions

Page 37: An Introduction to JavaScript: Week One

Functionsfunction greet(who) { return "hello" + who;}

greet("world");

Page 38: An Introduction to JavaScript: Week One

Functionsvar greet = function(who) { return "hello" + who;}

greet("world");

Page 39: An Introduction to JavaScript: Week One

Arrays and Objects

Page 40: An Introduction to JavaScript: Week One

Arraysvar a = [1, 2, "three"];

a[0]; // 1a[2]; // "three"a.length; // 3a[3]; // undefiend

Page 41: An Introduction to JavaScript: Week One

Arraysvar a = [1, 2, "three"];

a.push("four");a; // [1, 2, "three", "four"]

var last = a.pop();a; [1, 2, "three"]last; // "four"

var first = a.shift();a; [2, "three"]first; // 1

a.unshift("one");a; ["one", 2, "three"]

Page 42: An Introduction to JavaScript: Week One

Objectsvar coords = { x: 1, "y": 2 };

coords["x"]; // 1coords.y; // 2coords.z; // undefined

{ var: 1 }{ "var": 1 }

Page 43: An Introduction to JavaScript: Week One

Conditionals

Page 44: An Introduction to JavaScript: Week One

Conditionalshttp://www.flickr.com/photos/blahflowers/4765476166

Page 45: An Introduction to JavaScript: Week One

Conditionals

Page 46: An Introduction to JavaScript: Week One

Conditionals if the light is green cross the roadelse stop

Page 47: An Introduction to JavaScript: Week One

Conditionals if (light === 'green') { crossTheRoad();}else { stop();}

Page 48: An Introduction to JavaScript: Week One

Conditionals switch (light) {case 'blue':case 'green': crossTheRoad(); break;case 'red': stop(); break;default: lookConfused();}

Page 49: An Introduction to JavaScript: Week One

Loops

Page 50: An Introduction to JavaScript: Week One

Loopshttp://www.flickr.com/photos/blahflowers/4765476166

Page 51: An Introduction to JavaScript: Week One

Loops

Page 52: An Introduction to JavaScript: Week One

Loops while light is red waitcross the road

Page 53: An Introduction to JavaScript: Week One

Loops while (light === 'red') { wait();}crossTheRoad();

Page 54: An Introduction to JavaScript: Week One

Loops do { wait();} while (light === 'red');

crossTheRoad();

Page 55: An Introduction to JavaScript: Week One

Loops for (var i = 0; i < 8; i++) { potato(i);}more();

Page 56: An Introduction to JavaScript: Week One

Loops while (light === 'red') { if (axeMurder === true) { break; } wait();}crossTheRoad();

Page 57: An Introduction to JavaScript: Week One

Loops do { wait(); if (light === 'flashing green') { continue; }} while (light === 'red');crossTheRoad();

Page 58: An Introduction to JavaScript: Week One

Combined

Page 59: An Introduction to JavaScript: Week One

Combinedhttp://www.flickr.com/photos/davelevy/7190079438

Page 60: An Introduction to JavaScript: Week One

Combined

Page 61: An Introduction to JavaScript: Week One

Combined while light is not green if light is red wait if light is amber get readyGO GO GO!

Page 62: An Introduction to JavaScript: Week One

Combined while (light != 'green') { switch (light) { case "red": wait(); break; case "amber": getReady(); break; default: lookConfused(); }}goGoGo();

Page 63: An Introduction to JavaScript: Week One

Complex Objects

Page 64: An Introduction to JavaScript: Week One

Complex Objects var person = { name: "bob", greet: function() { return "hi " + this.name + "!"; }}

person.greet();

Page 65: An Introduction to JavaScript: Week One

Complex Objects var person = { name: "bob", greet: function() { return "hi " + this.name + "!"; }}

console.log(person.greet());

Page 66: An Introduction to JavaScript: Week One

Fizz Buzz

Page 67: An Introduction to JavaScript: Week One

Fizz Buzz•Count to 100 printing each number

•For numbers divisible by 3 print “Fizz” instead

•For numbers divisible by 5 print “Buzz” instead

•For numbers divisible by 3 and 5 print “FizzBuzz” instead

Page 68: An Introduction to JavaScript: Week One

Fizz Buzz

Page 69: An Introduction to JavaScript: Week One

Fizz Buzz

•Count to 100 printing each number

•For numbers divisible by 3 print “Fizz” instead

•For numbers divisible by 5 print “Buzz” instead

•For numbers divisible by 3 and 5 print “FizzBuzz” instead

Page 70: An Introduction to JavaScript: Week One

Thats All Folksemail: [email protected]

twitter: @danielknell

website: http://danielknell.co.uk/


Recommended