Presented by Heather Brysiewicz / @caligoanimus
Laptop ...with a browser! Text Editor - SublimeText
to follow along example at end - laptop with chrome or firefox with dev tools our example doesn't need text editor - sublime textReveal.js interactive examples
I'm going to be using a presentation tool called reveal.js its awesome because it actually runs in my browser which means it can run javascript code inside of my presentation if you're feeling daring, check it out. but in this talk there will be some interactive examples and this is how they work. good segway - javascripts pretty awesome because it can run anywherelaptop desktop tablet cell phone television arduino
why javascript? it runs basically anywhere large reach for what you create. don't need to buy an xbox to play your game, just load up a browser and you can share your game with anyoneall you need is a browser maybe a text editor
not only does it run everywhere, but it is easy to get started writing javascript because all you need is a browser that can understand and execute javascript if you use wordpress or tumblr, you can easily leave today and start messing around with javascript in the custom edit sections of those sites and add some awesome interactivity to your websitedata types conditionals, if/elseif/else, for loop, functions events and DOM api flipbook
boolean number string object kind of arrays...
for sake of this talk - 4 data types arrays, which are special objects but ultimately just objects with special methods and behaviors.
if (true) document.write("This is true! "); if (false) document.write("You won't ever see this :( ");Show Result
document.write(4 + 4); document.write(144 / 12); document.write(15 * 0.25);Show Result
document.write("I'm a string"); document.write("I'm a string... " + "And I am another string!");Show Result
{ name: "Heather" }
document.write({ name: "Heather" }); document.write({ name: "Heather" }.name);Show Result
document.write([1, 2, 3, 4, 5]); document.write([1, 2, 3, 4, 5][0]);Show Result
var myName = "Heather" document.write(myName); var myArray = [1, 2, 3, 4, 5]; document.write(myArray[0]);Show Result
== equal != not equal === strong (identity) equal !== strong (identity) not equal < less than > greater than <= less than or equal >= greater than or equal
operators you can use to compare items is an orange an apple? is 4 greater than 10
document.write(0 == ''); document.write(0 === '');Show Result
document.write(false != '0'); document.write(false !== '0');Show Result
document.write(0 < 4); document.write(4 < 4); document.write(0 > 4);Show Result
document.write(4 <= 4); document.write(7 >= 4); document.write(4 >= 4);Show Result
remember this example?
if (true) document.write("This is true! "); if (false) document.write("You won't ever see this :( ");This is true! here we used an if to check the value and do stuff but we can also say if this is true, do this, otherwise do that
var score = 0 if (score < 15) { document.write("Keep playing!"); } else { document.write("Game over!"); }
var score = 0 if (score == 14) { document.write("Game Point!"); } else if (score < 15) { document.write("Keep playing!"); } else { document.write("Game over!") }
var animals = ['kitten', 'unicorn', 'narwhale']; for (var i = 0; i < animals.length; i++) { document.write(animals[i] + ""); }Show Result
var printAnimals = function(animals) { for (var i = 0; i < animals.length; i++) { document.write(animals[i] + ""); } } var animals = ['kitten', 'unicorn', 'narwhale']; printAnimals(animals);Show Result
DOM API - getElementById
document.getElementById('dom-box').style.backgroundColor = '#bbcc66'; document.getElementById('dom-box').innerHTML = 'I am a box!';Do It!
DOM API - getElementsByTagName
var images = document.getElementsByTagName('img'); for (var i = 0; i < images.length; i++) { images[i].style.webkitFilter = 'grayscale(100%)'; }Do It!
onclick onmouseover onfocus onkeydown onscroll many, many more!
document.getElementById('dom-btn').onclick = function(e) { var images = document.getElementsByTagName('img'); for (var i = 0; i < images.length; i++) { images[i].style.webkitFilter = 'grayscale(100%)'; } }Do It!